UNIX and bashCommandsPrinceton University COS 217: Introduction to Programming Systems UNIX and bash Filenames and Directorynames /dir1/.../dirN Absolute dname dir1/.../dirN Relative dname /dir1/.../file Absolute fname dir1/.../file Relative fname Special Filename and Directoryname Characters fnameord*name * matches 0 or more characters fnameord?name ? matches any single character "fname or dname" " allows whitespace in a dname or fname 'fname or dname' ' allows whitespace in a dname or fname fnameord\'name Backslash (escape) character allows special characters in a dname or fname ~loginid Home directory of loginid ~ Your home directory .. Parent of working directory . Working directory Special Command Characters command 0< fname command < fname Redirect stdin to fname command 1> fname command > fname Redirect stdout to fname command 2> fname Redirect stderr to fname command 1> fname 2>&1 Redirect stdout and stderr to fname command1 | command2 Pipe from command1 to command2 ^d End of file command & Run command as a background process ^z Turn my foreground process into a stopped background process ^c Send a SIGINT signal ↑ Scroll backward through the command history list ↓ Scroll forward through the command history list !prefix Reissue the most recently issued command that begins with prefix !commandnum Reissue the command whose number is commandnum (see the “history” command) Page 1 of 3Commands Commands marked with “(bash)” are shell built-in commands. Commands marked with “(bin)” are executable binary files. Directory-Related Commands pwd (bash, bin) Print the name of the working directory to stdout cd [dname] (bash) Make dname the working directory ls [-la] [dname] (bin) List the contents of dname to stdout ls [-la] [fname] (bin) List the attributes of fname to stdout mkdir dname (bin) Create dname rmdir dname (bin) Destroy the empty directory dname File-Related Commands cat (bin) Concatenate (print) stdin to stdout cat fname ... (bin) Concatenate (print) fname ... to stdout more (bin) Print stdin to stdout one screen at a time more fname ... (bin) Print fname ... to stdout one screen at a time cp [-i] sourcefname targetfname (bin) Copy sourcefname to targetfname cp [-i] sourcefname targetdname (bin) Copy sourcefname to targetdname cp –r sourcedname targetdname (bin) Copy (recursively) sourcedname to targetdname mv [-i] sourcefname targetfname (bin) Rename sourcefname to targetfname mv [-i] sourcefname ... targetdname (bin) Move sourcefname ... to targetdname rm [-i] fname ... (bin) Remove fname ... rm –r [-i] dname [fname ...] (bin) Remove dname (recursively) and fname ... Configuration Commands source fname (bash) Execute the shell script in fname export variable=value (bash) Set environment variable to value export PATH=dname1:dname2:... (bash) Set the PATH environment variable indicating that bash should search dname1, dname2, ... to find commands that are specified as relative fnames export MANPATH=dname1:dname2:... (bash) Set the MANPATH environment variable indicating that the man command should search dname1, dname2, ... to find man pages variable=value (bash) Set shell variable to value PS1="\h:\w\$ " (bash) Set the PS1 shell variable to indicate that the command prompt should contain the name of the host computer, a colon, the name of the working directory, a dollar sign, and a space set –o shelloption (bash) Turn on shelloption set +o shelloption (bash) Turn off shelloption set –o ignoreeof (bash) Turn on the ignoreeof shell option to indicate that ^D entered at the bash prompt should not terminate bash set –o noclobber (bash) Turn on the noclobber shell option to indicate that bash should not overwrite files via redirection alias aliasname=string (bash) Create an alias definition such that aliasname as an abbreviation for string unalias aliasname (bash) Destroy the alias definition that defines aliasname Page 2 of 3File and Directory Permission Commands chmod mask fnameordname ... (bin) Set the permissions of fnameordname ... as indicated by mask umask mask (bash) Set the default permissions used when creating new files and directories as indicated by mask Software Development Commands (described throughout the course) xemacs (bin) Create or edit a text file using the xemacs editor gcc (bin) Preprocess, compile, assemble, and link a program gdb (bin) Debug a program make (bin) Build a program ar (bin) Create an archive file containing object code gprof (bin) Analyze the performance of a program Commands for Getting Help man [section] pagename (bin) Print to stdout the UNIX manual page (from section) whose name is pagename. Section 1 describes commands and utilities (e.g. cat, ls). Section 2 describes UNIX system calls (e.g. fork, pipe). Section 3 describes library functions (e.g. printf, strlen). apropos keyword (bin) Print to stdout each UNIX manual page NAME line that contains keyword Miscellaneous Commands history (bash) Print a numbered command history list to stdout passwd oldpassword (bin) Change my password from oldpassword wc [fname ...] (bin) Print a count of characters, words, and lines in fname ... (or stdin) to stdout date (bin) Print the date and time to stdout printenv [variable] (bin) Print the definition of environment variable (or of all environment variables) to stdout echo [arg ...] (bash, bin) Print arg ... to stdout who (bin) Print information about current users to stdout grep string fname ... (bin) Print each line of fname that contains string to stdout sort [fname] (bin) Print each line of fname (or stdin) in lexicographic order to stdout diff fname1 fname2 (bin) Print an indication of the differences between the contents of fname1 and fname2 to stdout which command (bin) Search PATH for command, and print the dname where it was found to stdout finger loginid (bin) Print information about user loginid to stdout Process Control Commands jobs (bash) List the names and jobnums of my background processes to stdout fg [%jobnum] (bash) Move my background process with the given jobnum to the foreground bg [%jobnum] (bash) Turn my stopped background process into a running background process kill [–signal] %jobnum (bash) Send signal to my background process with the given jobnum ps (bin) Display a list of my processes kill [–signal] pid (bin) Send signal to the process whose id is pid exit (bash) Exit bash
View Full Document