commands Basic syntax of shell commands UNIX or shell commands have a basic structure command -options target command comes first (such as cd or ls) any options (always proceeded by a – and also called flags) target (such as the file to move or the directory to list) These commands are written on the prompt (terminal command line). Where am I?: pwd Change directory: cd what files and directories are in my current directory: ls If I need to know more about a command: man command
ls ls ls –a ls –l ls –l –t ls -lS lists all files and directories in current working directory ls ls –a ls –l ls –l –t ls -lS lists all files and directories, including hidden files long format time sorted size sorted
permissions links permissions owner group size date filename group change permissions: chmod [u,g,o][+-][r,w,x] filename d - directory - - regular file r … read w … write x … execute drwxrw-rw- user other group
create, copy, delete directories mkdir dir_name rmdir dir_name rm –r dir_name cp –r dir_name dir_copy creates an empty directory named dir_name deletes an empty directory named dir_name deletes a directory named dir_name and its contents copies a directory named dir_name and its contents to a directory named dir_copy
create, copy, remove files touch file_name cp file_name file_copy mv file_name file_copy rm file_name creates an empty file named file_name copies file_name to file_copy renames file_name to file_copy deletes file file_name
change directories cd dir_name cd .. cd cd / cd - changes directory to dir_name goes to parent directory goes to home directory goes to root directory home is the parent directory of students goes to previous directory
absolute/relative paths Pathnames consist of file/directory names, separated by slashes / Any character except / is allowed. Use ''s around weird file names. Extensions are not meaningful to UNIX, only to applications Special file names .file_name . .. Absolute and relative file names - Absolute to the root (start with slash) (e.g. /home/wuchtys/Desktop) - Relative to the current working directory of the process (incl. . and ..) or home directory (e.g. ~/Desktop is equivalent to /home/wuchtys/Desktop)
less typing History history lists recent commands. !<number> redoes that command !<partial> redoes the most recent command that started with <partial> letters Globbing Describe to the shell (not OS) sets of file names with patterns ~ means the home directory ? means any character * means any string (including empty) [<letters>] means any one of the <letters> (except ...), which can also be a range ^ negates some glob expressions File name completion Many shells provide file name completion: Use tab key to expand partial file names