Newton Lab Unix Help

This page is still under construction.

Basic Unix Commands

Here are descriptons of a few Unix commands that are used frequently. The italic numbers next to the descriptions, are references to page numbers in "Unix in a Nutshell" by O'Reilly & Associates. ls: List the files in the current directory. 2-67 The example below shows the contents of the /usr directory. /usr% ls 4lib/ dict@ lost+found/ preserve@ tmp@ 5bin@ dt/ mail@ pub@ ucb/ X11R6/ games/ man@ sadm/ ucbinclude/ adm@ include/ net/ sbin/ ucblib/ aset/ kernel/ news@ share/ vmsys/ ls -l: List in long format, giving mode, number of links, owner, group, size in bytes, and time of last modifica- tion for each file (see above). If the file is a spe- cial file, the size field instead contains the major and minor device numbers rather than a size. If the file is a symbolic link, the filename is printed fol- lowed by and the pathname of the referenced file. ls -a Force printing of non-printable characters to be in the octal \ddd notation. ls -F Put a slash (/) after each filename if the file is a directory, an asterisk (*) if the file is an execut- able, and an at-sign (@) if the file is a symbolic link. NOTE: any of the above arguments to the ls command can be used any combination. /home/lab1x/rrothert/test% ls -alF total 1521 -rw------- 1 rrothert 71 May 17 11:02 #.article# drwx------ 2 rrothert 512 May 17 11:03 ./ drwxr-xr-x 11 rrothert 2048 May 17 11:02 ../ -rwxr-xr-x 1 rrothert 1034 May 17 11:03 .cshrc* -rwx------ 1 rrothert 1627 May 17 11:03 .login* -rw------- 1 rrothert 5954 May 17 11:02 1 -rw------- 1 rrothert 143 May 17 11:02 HTML.add -rw------- 1 rrothert 19 May 17 11:02 freenet -rw------- 1 rrothert 407 May 17 11:02 jobs -rw------- 1 rrothert 432224 May 17 11:02 mbox -rw------- 1 rrothert 0 May 17 11:02 phone -rw------- 1 rrothert 1073973 May 17 11:02 cd: Change directory. 2-14 The example below changes the current working directory to the directory specified in the cd argument. /usr% cd /home/lab1 /home/lab1% The cd command is also used to return to the "home" directory. Use no arguments to do this. /home/lab1x/rrothert/test% cd /home/lab1x/rrothert% To go up a directory, cd .. /home/lab1x/rrothert/test% cd .. /home/lab1x/rrothert% cp: Copy file1 to file2 , or copy one or more files to the same names under a directory. 2-19 /home/lab1x/rrothert/test% cp /home/lab1x/rrothert/test% ls To copy all the files of one directory to another directory, the special character * is used. Below, all the files in in the directory are copied to the foo directory. /home/lab1x/rrothert/test% cp * foo man: Display information from the on-line reference manuals. This is helpful when searching for more information on a particular command. 2-71 /home/lab1x/rrothert% man ls Reformatting page. Wait... done ls(1) User Commands ls(1) NAME ls - list contents of directory SYNOPSIS ls [ -abcCdfFgilLmnopqrRstux1 ] [ names ] AVAILABILITY SUNWcsu DESCRIPTION For each directory argument, ls lists the contents of the directory; for each file argument, ls repeats its name and any other information requested. The output is sorted alphabetically by default... When using man, the space bar scrolls down, b scrolls up, and / searches the man page for a specified string. more: Display the named files on a terminal, one screenful at a time. 2-73 When using more, the space bar scrolls down, b scrolls up, and / searches the man page for a specified string. mv: Command used to move files and directories around the system or to rename them. 2-74 Example 1 : Renaming a file /home/lab1x/rrothert/test% mv /home/lab1x/rrothert/test% ls # above the file gets renamed to Example 2 : moving a file to a different location. /home/lab1x/rrothert/test% mv /tmp # above the file gets moved to the /tmp directory lpr: Sends files to a printer. 2-65 Please see the lab monitor if you have questions about which printer to use. Use the -P option to specify a certain printer. /home/lab1x/rrothert% lpr -Pnp hey.txt lpq: Display the current printer que. lprm: Remove jobs from the printer que. rm: Delete one or more files. 2-91 rm -i Interactive. With this option, rm prompts for confirmation before removing any write-protected files. It overrides the -f option and remains in effect even if the standard input is not a terminal. rm -r: Recursively remove directories and subdirectories in the argument list. rm -f: USE WITH CAUTION!! Remove all files (whether write-protected or not) in a directory without prompting the user. In a write- protected directory, however, files are never removed (whatever their permissions are), but no messages are displayed. If the removal of a write-protected direc- tory is attempted, this option will not suppress an error message. /home/lab1x/rrothert% rm hey.txt

Special Characters

! & * ~ % ! : & : Used to put a process in the background immediately when it is executed. This allows you to use the shell while a process is being executed. Example: netscape & This example would start netscape and return a command prompt while netscape is executing * : This is a wild card symbol. Example: apollo:/src2/usr/bin# ls -l e* -rwxr-xr-t 2 root root 1453078 Dec 18 01:09 emacs* -rwxr-xr-t 2 root root 1453078 Dec 18 01:09 emacs-19.28* -rwxr-xr-x 1 root root 1088548 Dec 18 01:45 emacs.tty* -rwxr-xr-x 1 root root 8196 Dec 18 01:09 emacsclient* -rwxr-xr-x 1 root root 28676 Dec 18 01:09 etags* This example lists all the files in the /src2/usr/bin directory that starts with an e. Note the * next to each of the filenames. This indicates the file is an executable file. ~ : Specifies default home directory for a user. Example: apollo:/usr/src/linux> cd ~ apollo:~> pwd /home/ren Example 2 : apollo:~> cd ~ged apollo:~> pwd /home/ged % : Usefull when used in combination with 'jobs' and 'kill' Example: home/lab1x/rrothert% jobs [1] + Running netscape http://www [2] - Running emacs [3] Running netscape [4] Running xmaple /home/lab1x/rrothert% kill -9 %3 This would kill the 3rd netscape job.

fg: Put a process in the foreground. bg: Put a process in the backgroud. ps: report process status grep: Search a file for a pattern. kill: terminate a process gzip: compress or expand files

Commonly used applications...

vi : a visual editor pine: a Program for Internet News and Email ftp: file transfer program pico: simple text editor in the style of the Pine Composer emacs: editor,mail,news,more... lynx: a non graphical client to access the World Wide Web netscape: a graphical client to access the World Wide Web

Here are some more Unix help links.

Back to the The UT Newton Lab home page.

This page is maintained by Ryan Rothert
Questions, comments, and complaints may be directed to