Some Unix/Linux commands for use on the Mathematics Network Leemis Fall, 2008 Unix/Linux commands are typed at the shell (parent process) prompt. A typical command is just two letters (e.g., ls for listing files). Options are typically added with a dash. The file named fn is used generically here. Appending a command with & causes the command to be run in the background, which also displays the job number and process identifier (PID). Try the xclock command alone and with the &. Ctrl-c can be used to terminate a command (i.e., cancel child process) being executed. Hierarchy within X-windows: desktops, screens, windows. Prepending a backslash in front of a command indicates to look for the command from the filesystem rather than from an aliased version of the command contained in the .cshrc file in the main directory. Entry, exit, remote access logout logout (bye, exit, and Ctrl-d also work) rlogin hostname remote login to hostname rlogin hostname -l login remote login to hostname as login telnet hostname telnet to hostname ssh -X -l login hostname secure shell to hostname as login Ctrl-Alt-F1 text terminal Ctrl-Alt-F7 default terminal Listing files ls list files in directory ls a* list all files in directory starting with a ls a? list all two-character filenames starting with a ls a[1-8] list files a1, a2, ..., a8 (if they exist) ls -a list all files (including those beginning with .) ls -s list files with sizes ls -t list files ordered by time modified ls -ast list files using the previous three options ls -R list all subdirectories encountered ls ../dirname list files in dirname (same hierarchy level) ls -l long list, including access permissions, number of links, owner, group ownership, size in bytes, date and time last modified Removing, renaming, copying rm fn remove file fn rm -i fn1 fn2 interactively remove fn1, fn2 rm artwork/fig[2-7] remove fig2, ..., fig7 in subdirectory artwork rm *.log *.dvi *.aux remove all files with log, dvi, aux extensions mv fn1 fn2 move file fn1 to file fn2 (ie, rename) cp fn1 fn2 copy file fn1 to file fn2 cp fig2 part6/fig2 copy fig2 to subdirectory part6 cp file9 .. copy file9 to parent directory cp /usr/bin/fn $HOME copy /usr/bin/fn to home directory (avoids cd`s) cp /usr/fn1 $HOME/fn2 copy /usr/f1 to home directory renamed fn2 cp -r dir1 dir2 copy dir1 to dir2 (create subdirectories) File commands wc fn count the lines, words and characters in fn spell fn find spelling errors in fn ispell fn find spelling errors in fn and allow corrections sort fn sort the contents of fn (ASCII ordering) uniq fn generate only unique lines in the sorted file fn touch fn create file fn / set last modified date to now grep string fn find all occurrences of string in fn grep -i string fn find all occurrences of string in fn(ignore case) grep 'str w/blanks' * find all occurrences of str w/blanks in all files gv fn preview a postscript file fn (ghostview in unix) ps2ps fn1.ps fn2.ps convert from ps to ps, cleaning up font problems ps2pdf fn1.ps fn2.pdf convert from ps to pdf dvipdf fn1.dvi fn2.pdf convert from dvi to pdf acroread fn.pdf view a postscript file fn.pdf xpdf fn.pdf view a postscript file fn.pdf xv fn.jpg display a jpg file fn.jpg convert fn.jpg fn.pdf convert fn.jpg to fn.pdf ooffice fn use Micro$oft product emulators on fn file fn show type of file whereis command show location of a command which command show location of a command diff fn1 fn2 show differences between fn1 and fn2 cat fn show contents of fn cat /etc/hosts shows list of IP addresses tail fn show last few lines of fn tail -n fn show last num_lines lines of fn more fn print fn to screen by page (return for next line, space bar for next screen, q for quit, d for next halfscreen, b for previous screen, h for help) less fn alternative to more (allows you to back up) Printing (the printer name is hp113) lpr fn send fn to default printer lpr -Pprintername fn send fn to printer named printername enscript fn send fn to default printer w/ a different format enscript -2GrE fn send fn to default printer w/ a different format a2ps fn send fn to default printer w/ a different format lpq show queue for default printer lpq -Pprintername show queue for printername (also list job no, jn) lprm -Pprintername jn delete job number jn from print queue On-line help man command manual entry on a command ( -k option useful) man ls manual entry on ls man man manual entry on man apropos command search manual entries on a command apropos mail search manual entries on mail apropos 'copy files' search manual entries on copying files whatis command shows what a command does Mail and communications mail check for incoming electronic mail mail username e-mail to username (end mail with . or Ctrl-d) mail username < fn send fn to username thunderbird x-window based mailer pine another character-based mailer mutt another character-based mailer mutt -a fn login send fn as attachment to login (uses vi editor) Miscellaneous who shows who is logged in who am i identity check passwd change password for your account hostname indicates the machine you are on finger shows all users currently logged in finger username show user information on username finger wm@cs.wm.edu show information on Weizhen Mao date gives date and time xclock an analog clock xeyes eyes that look at the mouse position xbiff new e-mail indicator printenv display environmental variables env display environmental variables setenv TERM vt100 set the terminal type to vt100 ftp hostname use ftp (file transfer program) on hostname which gcc shows where gcc lies, provided it is in path Directories mkdir dirname make directory named dirname cd change to home directory cd dirname change directory to dirname cd .. move up one level in directory hierarchy cd ../jones change to jones (same level as current directory) cd /usr/local change to /usr/local (relative to / directory) cd $HOME/networks change to networks (relative to home directory) cd - change to the previous directory pwd print working directory rmdir dirname remove directory dirname(directory must be empty) mv dir1 dir2 change directory name pushd dirname change directory to dirname, but keep current directory on the stack popd change back to previous directory Killing processes ps list processes ps -ux list processes showing more detail kill PID kill a process (PID given from ps command) kill -l PID kill a process (-9 option is even stronger) Disk usage du disk usage starting from working directory df disk capacities & utilization df -h disk capacities & utilization (-h alters units) quota -v disk usage and quota free shows amount of free space available Web browsers firefox firefox browser rm -rf .firefox/cache cleanup firefox cache mozilla mozilla browser rm -rf .mozilla/cache cleanup mozilla cache Editors vi fn use vi editor to edit fn gvim fn use gvim editor to edit fn emacs fn use emacs editor to edit fn pico fn use pico editor to edit fn kile fn use kile editor (kde editor w/LaTeX capability) sed -i -e cmfn fn use commands in cmfn to edit fn (-i for in place) awk fn pattern scanning and processing language Wildcards (* matches any characters, ? matches a single character, [ ... ] matches any character in list or range) ls *.tex list all files with tex extension cat figure?? > figs concatenate some 8-character files to figures rm fig[1-7] remove fig1, fig2, ..., fig7 if they exist grep '[Jj]ohn' addresses find John or john in the file named addresses grep '19[5-9][0-9]\|200[0-4]' fn* find all dates 1950-2004 in fn* Permissions Type of permission r: read w: write x: execute Permission granted to whom u: user g: group o: others a: all (user, group, and others) chmod mode fn change permissions on file fn using mode chmod mode directory_name change permissions on directory_name using mode chmod u+x fn add execute permission for the user on file fn chmod g+r fn add read permission for the group on file fn chmod a+r *.tex add read permission for everyone on all tex files chmod g-wx fn remove write and execute permissions for group chmod 755 * user is rwx, group is rx, others are rx chmod 700 fn user is rwx, group and others have no permission Repeating commands history give a list of previous commands !! repeat previous command !string repeat most recent command beginning with string !47 repeat command number 47 (execute history first) up_arrow scroll upward through previous commands down_arrow scroll downward through previous commands Redirecting output ls -l > listfile place long listing in listfile cat memo? > mymemos concatenate memo files and place in mymemos who > people place output of who command in people ls -a >> listfile append listfile with output from ls -a sort fn >> sortedfn append sortedfn with the output from sort Piping finger | wc -l count the number of users ps -aux | grep joe | more find the string joe in ps & pipe output to more diff fn1 fn2 | lpr print the differences between fn1 and fn2 File compression tar -czvf fn.tgz f1 f2 d1 zip files f1, f2 and files in dir d1 as fn.tgz tar -xvf fn.tgz unzips files contained in the tarball tgz tar -tzvf fn.tgz list files in archive fn.tgz gzip fn zip fn gunzip fn unzips fn unzip fn unzips fn Helpful hidden files (in home directory) .vacation.msg bounces message while you are away from e-mail run the vacation program by typing vacation at the shell prompt .forward forwards mail to another e-mail address contained in this file .exrc common abbreviations for typing in vi. typical contents: set number set wm=10 ab 1n $i = 1, 2, \ldots , n$ ab bs both sides ab ch Chapter ab ci confidence interval ab rhs right hand side ab sm \sum_{i=1}^n ab ttt total time on test ab wm The College of William \& Mary ab wrt with respect to .plan information about you (contact information, etc.) .cshrc abbreviations for commands and other systems information. sample contents: set history=40 set prompt="`whoami`@`hostname`> " alias gh ghostview alias h history alias mroe more alias c 'chmod 700 *' alias cleanup 'rm *.aux *.log *.dvi' alias cls 'clear' .mailrc mailing addresses. sample contents: alias amydudley adudley@synergyinc.com alias andyglen andylisaglen@hotmail.com alias annwomack abwoma@mail.wmvm1.edu # ###################################### # Retired math faculty on math network # # ###################################### # alias hugheasler hbeasl@math.wm.edu alias larryrabinowitz lxrabi@math.wm.edu # ##################################### # Adjunct instructors on math network # # ##################################### # alias dougnark dmnark@math.wm.edu alias craighunter c.a.hunter@LaRC.nasa.gov alias michaellewis buckaroo@icase.edu alias math.fac charliejohnson ckli ... alias math.ret hugheasler larryrabinowitz set askcc hold set SHELL csh set metoo don't forget to execute the shell command: source $HOME/.mailrc when a modification is made Running FORTRAN (Unix only) f77 fn.f compiles fn.f (.f suffix required) object code in fn.o f77 -o executablename fn.f use executablename rather than a.out ./a.out execute (run) file a.out keyboard is input, screen is output ./a.out & execute (run) file a.out in the background ./a.out < fn execute file a.out using fn as input ./a.out > fn execute file a.out writing output to fn ./a.out < infile > outfile execute file a.out using infile as input and writing output to outfile ./a.out >> fn execute file a.out and append output to fn The U(0,1) generator is rand(0) Running C and C++ cc fn.c compiles C source fn.c (.c suffix required) ./a.out execute (run) file a.out g++ fn.c compiles C++ source fn.c (.c suffix required) g++ -c fn1.c compiles C++ implementation file (must have corresponding fn1.h file) for a library g++ fn.c fn1.o compiles C++ source fn.c that uses library code from files fn1.h and fn1.c g++ -g fn.c compile with intent to use debugger gdb debugger (the compilation must include -g flag) break nn create a break point in the program prior to line nn in the source break FunctionName create a break point in the program prior to the call to FunctionName run begin running the program n step to next line print VariableName display the value of VariableName quit leave the debugger Exporting graphics hostname find Linux machine name (for set env later) ssh -Y secure shell (automatically exports graphics) xhost machinename allow rlogin on machinename (m1, m2, m4, m5) rlogin machinename remote login to machinename (m1, m2, m4, m5) setenv DISPLAY hstnm:0.0 send display graphics to your screen External files (pseudo-dos commands) mdir list files on the floppy drive mcopy * a: copy current linux directory to the floppy drive mdel fn delete filename on the floppy drive mren fn1 fn2 rename fn1 to fn2 on the floppy drive Homepages Place your homepage in a file named index.html in a subdirectory named public_html off of your main directory. Getting help For systems assistance (not assistance with programming or assistance using a package), you may e-mail the techie at techie@cs.wm.edu once local resources have been exhausted. Tutorial Click the UNIX Lab Manual on the W&M Computer Science Department home page www.cs.wm.edu, which gives a tutorial on the Unix operating system. IP addresses The IP addresses of machines on the Mathematics network are located in the file /etc/hosts. These can be valuable when the name server is not available. The command: ping machinename lists the IP address.