UNIX Reference Card Create a Directory Called Options: -I Interactive Mode
Total Page:16
File Type:pdf, Size:1020Kb
File System Manipulation Move (Rename) Files and Directories mv present-filename new-filename to rename a file Create (or Make) a Directory mv source-filename destination-directory to move a file into another directory mkdir directory-name directory-name UNIX Reference Card create a directory called options: -i interactive mode. Must confirm file overwrites. Anatomy of a Unix Command Look at a File Copy Files more filename man display file contents, same navigation as cp source-filename destination-filename to copy a file into command-name -option(s) filename(s) or arguments head filename display first ten lines of a file another file tail filename display last ten lines of a file Example: wc -l sample cp source-filename destination-directory to copy a file into another directory : options options: The first word of the command line is usually the command name. This -# replace # with a number to specify how many lines to show is followed by the options, if any, then the filenames, directory name, or -i interactive mode. Must confirm overwrites. Note: this other arguments, if any, and then a RETURN. Options are usually pre- option is automatically used on all IT’s systems. -R recursive delete ceded by a dash and you may use more than one option per command. List Files and Directories The examples on this reference card use bold case for command names Remove (Delete) Files and Directories and options and italics for arguments and filenames. ls lists contents of current directory ls directory-name list contents of directory rm filename to remove a file rmdir directory-name to remove an Important Note about UNIX Commands empty directory : options options: -a list all files including files that start with “.” UNIX commands are case sensitive. Type commands exactly as shown; -i interactive mode. Prompt for confirmation. Note: this -s list size of files (in kilobytes) most UNIX commands are lower case. File and directory names can be is option is automatically set up on all IT’s systems. -l long list, shows ownership, permissions, and links lower, upper, or mixed case but must be typed exactly as listed. Com- -l -g lists the group of each file or directory when used with -l mands prefaced by a ^ (caret) mean to hold down the CONTROL key Change File Access Permissions -t list files chronologically and then press the indicated character. -F append “*” to executable file name, “/” to directory name, chmod [who op permission] filename and “@” to symbolic link who can be any combination of: -u On-line Documentation list files using time of last access instead of time of last u (user) modification g (group) man command display on-line manual pages about command o (other) pwd Navigation: SPACEBAR moves down 1 screen (display the name of present working directory) a (all) (i.e. ugo) RETURN move down 1 line ^d move down 1/2 screen Change Working Directory op adds or takes away permission, and can be: ^b move up 1/2 screen + (add permission), cd q exit to change to your home directory - (remove permission), or cd directory-name h help to change to another directory = (set to exactly this permission) examples: permission can be any combination of Printing cd test change to the directory named test r (read) w (write) lprloc lists available printers Directory Abbreviation x (execute) setenv PRINTER printer set the default printer pcpasswd initialize SAMBA password for lab ~ home directory (tilde) Ex: chmod a+x filename (makes filename executable by everyone) printing /login; only works on Owlnet’s ~username another user’s home directory short-earred and long-earred servers http://www.owlnet.rice.edu/webprint.shtml . current or working directory Shell Tools web-based printing; view current charges .. parent of working directory lpr option filename print file Wild Cards lpq option check status of print queue ? single character wild card lprm option remove jobs from printer queue * arbitrary number of characters options: -Pprinter specify a printer other than the default History: Command Repetition Run Command in Background: Job Control Program Compilation history display list of most recent commands To run a command in the background, as opposed to the more common f90 filename.f !! repeat the entire last command line at any point method of running commands in the foreground, append an & to the FORTRAN compiler (also f77 code) cc filename.c in the current command line end of a command string. Then, you can type more commands to the C compiler gcc !$ repeat the last word of previous command command prompt, or even run more commands in the background for filename.C C compiler (other suffixes: .cc, .cxx, .cpp, .c++) g++ line at any point in current command line simultaneous command execution. filename.c++ C++ compiler pc filename.p !^ repeat first argument from previous command Pascal compiler line at any point in the current command line Control-Z stop (interrupt) foreground job ! n repeat command line n jobs list of background jobs options: -o filename filename !!:p display previous command bg run a stopped job in the background direct output of program to -l library library !string command beginning with string fg resume stopped job in the background include in program compilation !* repeat all arguments to previous command File Operations Command I/O User Information and Helpful Commands > Search for Patterns in Files command output redirection (create new) env lists your environment settings >> command output redirection (append) who lists users on the local system < grep search-string filename [filename...] to find and type out lines con- command input redirection (from file) finger [email protected] << taining the string in a file command input (from script or standard input) looks up information on another user options: -v type out lines that don’t contain the string (invert the search) Alias clear clears screen ntalk [email protected] alias alias-string command-string Counting Words in a File talk to another user lprloc wc filename counts the number of words, lines, or characters in a file shows names and locations of printers Alias abbreviates a command string with an alias string. For multi- stty sane resets terminal characteristics to a command strings, enclose commands in quotes. options: -w words -l lines usable set stty display terminal characteristics alias -m characters Example: shut chmod go-rwx date displays current time and date Compare Files cal year for yearly calendar To use the aliased command shut on a file, and turn off read, write, and cal ## #### for monthly calendar executable permissions for all users except yourself, type shut filename. (month-year diff filename1 filename2 compares contents of filename1 and filename2 ) ssh host.domain user interface to a remote system Process Control on a line-by-line basis File Transfer which command locate a command; display its pathname Process Status spell filename report spelling errors mail address sends mail to user at the specified address (using the for- ispell filename interactive spell-checker ps (display the status of the current processes) mat is [email protected]). ^d terminates input and sends message. options: echo $path inspect your search path -a include processes owned by other users ftp host.domain use file transfer protocol to connect to remote host -g display all processes computer. Type ? for commands. bc basic calculator (^d to exit) -u display user-oriented processes -x include processes with no controlling terminals Compress Files du display the number of disk blocks used -gx display all of your local processes per directory or file compress filename compress file and rename it filename.Z du -s display your total disk usage kill id-number terminate a process owned by you uncompress filename.Z decompress file and rename filename quota -v display your disk quota and usage The id-number (PID-Process ID) can be gzip filename compress file and rename it filename.gz found by first using the ps command. gunzip filename.Z decompress file and rename filename.