User Tools

Site Tools


info:basic_commands

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
info:basic_commands [2009/09/17 22:17] – created moritzinfo:basic_commands [2012/02/25 21:10] (current) – Added rsync intro hartmut
Line 3: Line 3:
  
 ===== Working with Files ===== ===== Working with Files =====
-  * <code>ls</code> lists files in current directory. Use <code>ls -al</code> to list all files (including hidden = starting with .) in a long listing. +  * ''ls'' lists files in current directory. Use ''ls -al'' to list all files (including hidden = starting with .) in a long listing. 
-  * <code>mkdir</code> creates a directory. Specify the directory name after the command. +  * ''mkdir'' creates a directory. Specify the directory name after the command. 
-  * <code>rm</code> removes files and directories. If directories need to be removed, the <code>-r</code> option must be specified. To force operation, add <code>-f</code>. The last parameters are the files and directories that are to be deleted. Make sure that there are no wrong directories listed! A call to <code>rm -rf /</code> as root is not a good thing. +  * ''rm'' removes files and directories. If directories need to be removed, the ''-r'' option must be specified. To force operation, add ''-f''. The last parameters are the files and directories that are to be deleted. Make sure that there are no wrong directories listed! A call to ''rm -rf /'' as root is not a good thing. 
-  * <code>file</code> reveals what content type a file is. Use it to test if a file is text, image, binary or whatever. +  * ''mv'' moves a file, where path is relative to current directory: mv [path]filename [path]filname 
-  * <code>sudo</code> starts a process with super user (=root) capabilities. To start a root shell, use <code>sudo su</code>. If <code>sudo</code> is not installed, use <code>su</code> instead. It requires not the current user's password but the root password. +  * ''file'' reveals what content type a file is. Use it to test if a file is text, image, binary or whatever. 
-  * <code>less</code> helps to look at what a file stores. +  * ''find'' and ''rm'' can be used in combination to delete files found by ''find''. e.g. this will recursively remove all files with extension ''.txt'' in the current directory: ''find . -name \*.txt -print0 | xargs -0 rm''\\ As an alternative, it is possible to use some shell features: ''rm $(find -name \*.txt)'' 
-  * <code>cat</code> reads a file and prints it to <code>stdout</code> (the console if invoked as-is.) +  * ''sudo'' starts a process with super user (=root) capabilities. To start a root shell, use ''sudo su''. If ''sudo'' is not installed, use ''su'' instead. It requires not the current user's password but the root password. 
-  * <code>locate</code> locates all files that contain a given string. +  * ''less'' helps to look at what a file stores. 
-  * <code>grep</code> searches input for matching lines. To search all files in the current directory (and sub directories), use <code>grep -r . -e "text"</code>+  * ''cat'' reads a file and prints it to ''stdout'' (the console if invoked as-is.) To read from STDIN, pass ''-'' as the file to read. This can be used to create a file by entering its content in the console. Use ''cat - > new_file'' and paste the content to quickly create a new file with content. To end the file, press Ctrl+D, which produces the EOF-character. 
-  * <code>man</code> shows the manual for some command. Sometimes <code>info</code> shows a more detailed documentation. +  * ''locate'' locates all files that contain a given string. 
-  * <code>dmesg</code> prints kernel messages.+  * ''grep'' searches input for matching lines. To search all files in the current directory (and sub directories), use ''grep -r . -e "text"''
 +  * ''man'' shows the manual for some command. Sometimes ''info'' shows a more detailed documentation. 
 +  * ''dmesg'' prints kernel messages. 
 + 
 +===== Networking Tools ===== 
 +==== HTTP/FTP ==== 
 +  * Use ''wget'' to download files from HTTP and FTP. The tool allows recursive downloading, i.e. also fetch outgoing links from some HTML page. To restrict the files downloaded to a certain type (by file suffix), use the ''-A'' option: <code>wget -r http://some.host/path/to/file.html -A pdf</code> downloads all PDFs referenced by the HTML file. 
 +==== rsync ==== 
 +  * To upload files from your machine to another via ssl, one tool that can be used is ''rsync''. It allows recursive uploading, can be configured to upload changed or new files only, can optionally delete remote files that are no longer existing locally, and is very nice to your bandwith. 
 + 
 +=== Example === 
 +* This is a script to upload a complete directory recursively (local copy of website to web server). 
 +The local directory is ''gallery'', this is also the place where the script resides. The remote username 
 +is ''user'' and should be replaced by an existing one. Also, the server ''server.xx'' and the server directory have to be adapted. 
 + 
 +The rsync options used here: ''-a'': keep a lot of attributes (owner, permissions etc.); ''-z'': compress; ''-v'': verbose; ''-r'': recurse into subdirectories; ''--update'': only upload changed or added files; ''--delete'': delete remote files no 
 +longer available locally; and finally: ''--delay-updates'': makes rsync postpone all changes until the run is finished, which makes a lot of sense when updating live websites. 
 + 
 +If you comment out the second ''myoption='' line and uncomment the first one, the ''--dry-run'' option lets you simulate what rsync would do without actually harming anything. 
 + 
 +<code> 
 +#! /bin/sh 
 +#comment out --dry-run to get it working 
 +#myoption=--dry-run # don't put spaces around the = 
 +myoption= #this resets the variable 
 +echo "--> gallery dir" 
 +rsync -razv --update --delete $myoption --delay-updates gallery user@server.xx:/var/www/de.baz.foo/ 
 +</code> 
  
 ===== Piping ===== ===== Piping =====
-The output of one command can be piped into the input of another command. This is done by the pipe operator <code>|</code>. To search kernel messages for some string, use <code>dmesg | grep string</code>.+The output of one command can be piped into the input of another command. This is done by the pipe operator ''|''. To search kernel messages for some string, use ''dmesg | grep string''
 + 
 +Additionally, the STDOUT (1) and STDERR (2) streams can also be redirected. To redirect the STDERR output to STDOUT, use: ''command 2>&1 ...''. This can be used in combination with piping.
  
  
info/basic_commands.1253218630.txt.gz · Last modified: 2009/09/17 22:17 by moritz

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki