Shell Reference
Basic Commands
catdisplays the contents of its inputs.cd pathchanges the current working directory.cp old newcopies a file.findfinds files with specific properties that match patterns.grepselects lines in files that match patterns.headdisplays the first few lines of its input.ls pathprints a listing of a specific file or directory;lson its own lists the current working directory.man commanddisplays the manual page for a given command.mkdir pathcreates a new directory.mv old newmoves (renames) a file or directory.pwdprints the user’s current working directory.rm pathremoves (deletes) a file.rmdir pathremoves (deletes) an empty directory.sortsorts its inputs.taildisplays the last few lines of its input.touch pathcreates an empty file if it doesn’t already exist.wccounts lines, words, and characters in its inputs.whoamishows the user’s current identity.
Paths
/path/from/rootis an absolute path./on its own refers to the root of the filesystem.path/without/leading/slashis a relative path..refers to the current directory,..to its parent.*matches zero or more characters in a filename, so*.txtmatches all files ending in.txt.?matches any single character in a filename, so?.txtmatchesa.txtbut notany.txt.
Combining Commands
command > fileredirects a command’s output to a file.first | secondconnects the output of the first command to the input of the second.A
forloop repeats commands once for every thing in a list:for variable in name_1 name_2 name_3 do ...commands refering to $variable... done- Use
$nameto expand a variable (i.e., get its value). historydisplays recent commands, and!numberto repeat a command by number.bash filenameruns commands saved infilename.$*refers to all of a shell script’s command-line parameters.$1,$2, etc., refer to specified command-line parameters.$(command)inserts a command’s output in place.