<<

San Diego State University System Commands Move (Rename) Files and Directories Rohan Reference Card 2/7/2003 RN Create () a Directory old-name new-name rename old to new mv filename directory move file into directory Anatomy of a Unix directory-name create a directory Option: -p Create any non-existing parent directories Copy Files Command-name -options(s) filename(s) or arguments Look a File filename copy-name copy a file into a new filename Example: -l /etc/motd cp filename directory copy a file into a directory filename display file contents, similar to Options: The first word of the command line is usually the Options: -i confirm before overwriting existing file. command name. This may be followed by options, SPACEBAR moves down a screen -R recursive copy (including directories) filenames, directory name, or other arguments, and then b moves back a screen (up) a RETURN. Option(s) are usually preceded by a dash. ^F follow a file as it grows Remove (Delete) Files and Directories The examples in this document use bold case for /text and highlight text command names and options, and italics for arguments ?text find (going up) and highlight text filename to remove a file and filenames. q directory to remove an empty directory h Options: UNIX is Case Sensitive -i interactive, prompts for confirmation head file display first 10 lines of a file UNIX commands are lower case. File and file sort a file alphabetically ( -n sort numerically Recover Files and Directories directory names can be lower, upper or mixed case, and -r reverse sort ) must be typed exactly as listed. Commands prefaced by file display last 10 lines of a file Backups are run every night around 3AM. Files can be a ^ (caret) mean hold down the CONTROL key while tail –f file display new lines as they appear in the file recovered if they existed while the backup was running. pressing the indicated character. Change to the directory where the old file used to exist and List Files and Directories recover. The recover program will prompt “recover>”. Documentation List files on the most recent backup by typing . Use ls lists contents of current directory changetime month day to restore from a given day. Select man command Manual pages for command ls directory-name lists contents of directory files for recovery with add filename(s). When finished, type Navigation: SPACEBAR moves down a screen recover to restore the file(s). Expect to 5 or 10 minutes. q exit Options: Type quit to exit. h help -a lists all files including files starting with ‘.’ -l long list, shows permissions, owner, size Change File Access Permissions GNU Project documentation -t list files chronologically Navigation: SPACEBAR move down a screen -F append ‘*’ to executables, ‘/’ to directories [ op access] filename DEL move back a screen -R recursively list files and directories who can be any combination of: TAB skip to next u user (user is the owner of the file) RETURN follows link Change Working Directory g group o other q exit change to your home directory h help tutorial a all (ie: ugo) cd directory-name change to another directory op add or removes access, and can be: print the name of the working directory Printing + add access Directory Abbreviations - remove access Setenv PRINTER printer set the default printer access can be any combination of: lp option file(s) print filename(s) ~ home directory (tilde) r read 4 2 ~username another user’s home directory Printer lp is the free line printer in BA-134 x execute 1 Printer laser is 10 cents/page in BA-110 . current or working directory : chmod a+x filename (Add execute access for everyone) Printer scc is 10 cents/page in Student Computing Center .. parent directory chmod 711 filename (Set access to rwx for user, execute for group and other.) Shell Tools Concatenate and Display Files Compilers

Wild Cards file(s) reads each file in sequence and displays them. cc file.c C compiler, use gcc for GNU C compiler ? single character wild card Options: -n number lines, -vt display non-printing characters CC file.cc C++ compiler, g++ for GNU C++ compiler * any number of characters f90 file.f Fortran 90 compiler (and f77 code) Compare Files f95 file.f Fortran 95 compiler : Command Repetition Options: -o file compile as file instead of a.out file1 file2 compares the contents of file1 and file2 and -l library include library in compilation history display list of recent commands displays the lines that are different. javac file Java compiler for java interpreter !! repeat the last command line !$ repeat the last word of the prior command Counting Words in a File Debuggers !n repeat command line n !string repeat command beginning with string wc file counts the number of works, lines, or characters dbx file compiler command line debugger Options: -w words, -l lines, -c characters workshop file compiler GUI debugger Command Redirection gdb file GNU compiler command line debugger Compress Files ddd file GNU compiler GUI debugger > file redirect output to a new file Helpful Commands >> file append output to existing file compress file compress file and rename it file.Z < file redirect input from file uncompress file.Z uncompress file.Z and rename it file ^C abort command (some commands trap ^C) | pipe output of one command into another gzip file compress file and rename it file.gz Ex: ls -l | less ^L redraw screen (works in , less, man, ) gunzip file.gz uncompress file.gz or file.Z and rename file list environmental variables and values Aliases $path list the command search path Process Control file show where file is on system abbreviation command create alias command show where command is located alias abbreviation show alias Process Status unalias abbreviation remove alias chfn change your finger info display the status of current shell’s processes finger user show info about user (also displays .plan) Alias creates an abbreviation for a command line. For Options: change your login password multiple commands, enclose the commands in quotes. -e display every process (owned by you or others) who list users on the system Ex: alias ls ls -F (execute ls -F when ls is used) -f display additional info w list system load and users alias big “ -sk .[A-z]* * | sort -rn | head” -u user show all processes owned by user top list system info, and top CPU users (show biggest files and directories) PID soft kill, terminate PID with SIGTERM. May be clear screen File Operations trapped. (Process ID is found by using the ps year show calendar for year (use 2003 not 03) command) Every command has it’s own PID. date show current and date Search for Patterns in Files kill –9 PID hard kill, terminates PID with SIGKILL du -k show disk usage in current directory find . –size +1000 –ls show files over 500KB in size pattern [filenames(s)] display lines matching the Job (Process) Control nsrwatch show status of tape backup robot pattern in the file(s). quota –v show your disk quota Options: A command may be run in the background by appending an & ssh connect to remote system host (tunnels X) -v display lines that don’t match to the end of the command. Then other commands can be -i match upper or lower case typed (in the foreground) while the background command is emacs powerful text and GUI editor running. pico simple text editor Patterns can be any combination of: vim (vi) vi improved visual editor string match string anywhere in a line ^Z stop foreground job (interrupt) vilearn tutorial on how to use the vi editor ^string match if string begins a line jobs list any background jobs string$ match if string ends a line bg resume a stopped job in the background elm text based program ab[c,d] match list, ie: abc or abd fg resume a job in the foreground text based mail program ab[A-D] match range, ie: abA, abB, abC, abD fg %n resume job n in the foreground tin USENET News reader