...
- mkdir -p <dirname> create directory <dirname>. -p says to create any needed subdirectories also.
- rm <file> deletes a file. This is permanent - not a "trash can" deletion.
- ln -s <file_or_directory> creates a symbolic (-s) link with the name corresponding to the last name in <file_or_directory> path.
- touch <file> - create an empty file
...
- cp <source> <destination> copies the file <source> to the location and/or file name <destination>.
- Using . (period) means "here, with the same name".
- cp -r <dirname> <destination> will recursively copy the directory dirname and all its contents to the directory destination.
- scp <user>@<host>:<source_path> <destination_path>
- Works just like cp but copies source from the user user's directory on remote machine host to the local file destination
- wget <url> fetches a file from a valid URL (e.g. http, https, ftp).
- rsync <source_directory>/ <target_directory>/
- Recursively copies <source_directory> contents to <target_directory>, but only if <source_directory> files are newer or don't yet exist in <target_directory>
Remote path syntax (<user>@<host>:<absolute_or_home-relative_path>) can be used for either source or target (but not both).
Miscellaneous commands
- wc -l <file> reports the number of lines (-l) in <file>
- history xx
- history lists your command history to the terminal
- redirect to a file to save a history of the commands executed in a shell session
- pipe to grep to search for a particular command
- which <pgm> searches all $PATH directories to find <pgm> and reports its full pathnamewhich xx
Advanced commands
- cutxx
- sort xx
- uniq xx
- grep xx
- -f <field_number(s)> <file> extracts one or more fields (-f) from each line of tab-delimited <file>
- sort sorts its input using an efficient algorithm
- by default sorts each line lexically, but one or more fields to sort can be specified with one or more -k <field_number> options
- options to sort numerically (-n), or numbers-inside-text (version sort -V)
- uniq -c counts groupings of its input (which must be sorted) and reports the text and count for each group
- use cut | sort | uniq -c for a quick-and-dirty histogram
- grep -P '<pattern>' searches for <pattern> in its input and outputs only lines containing it
- always enclose <pattern> in single quotes to inhibit shell evaluation
- -P says use Perl patterns, which are much more powerful than standard grep patterns
- <pattern> can contain special match "meta-characters" such as:
- ^ – matches beginning of line
- $ – matches end of line
- ? – matches any single character
- * – matches 0 or more characters
- + – matches 1 or more characters
- awk '<script>' a powerful scripting language that is easily invoked from the command line
- <script> is applied to each line of input (generally piped in)
- always enclose <script> in single quotes to inhibit shell evaluation
- General structure of an awk script:
- {BEGIN <expressions>} – use to initialize variables before any script body lines are executed
- e.g. {BEGIN FS="\t"; OFS="\t"; sum=0} says to use tab (\t) as the input (FS) and output (OFS) field separator (default is a space), and initialize the variable sum to 0.
- {<body expressions>} – expressions to apply to each line of input
- use $1, $2, etc. to pick out specific input fields
- e.g. {print $3,$4} outputs fields 3 and 4 of the input
- {END <expressions>} – executed after all input is complete (e.g. print a sum)
- {BEGIN <expressions>} – use to initialize variables before any script body lines are executed
- <script> is applied to each line of input (generally piped in)