The following is a list of the UNIX basic commands, practice by yourself, and make sure you understand all of them. This list can be roughly divided into the following categories:
$ pwd /users1/ehuang/shell_demo
$ who root pts/3 Feb 2 08:33 ehuang pts/9 Feb 2 18:22 (acc5) jerry pts/8 Feb 2 11:55 (acc8) root pts/5 Feb 2 08:33 ... ... $ whoami ehuang
$ hostname acc5.its.brooklyn.cuny.edu
$ date Mon Feb 2 18:26:21 EST 1998
$ uname -a SunOS butler1.its.brooklyn.cuny.edu 5.6 Generic sun4m sparc
$ ls faq.tar test1 test2 $ ls -l -rw------- 1 ehuang adjunct 466944 Jan 31 21:04 faq.tar -rw------- 1 ehuang adjunct 20 Feb 2 18:23 test1 -rw------- 1 ehuang adjunct 20 Feb 2 18:23 test2 $ ls -a . .. faq.tar test1 test2 $ ls -lt total 932 -rw------- 1 ehuang adjunct 20 Feb 2 18:23 test2 -rw------- 1 ehuang adjunct 20 Feb 2 18:23 test1 -rw------- 1 ehuang adjunct 466944 Jan 31 21:04 faq.tar $ ls -lratF total 936 -rw------- 1 ehuang adjunct 466944 Jan 31 21:04 faq.tar drwx------ 15 ehuang adjunct 1024 Feb 2 18:22 ../ -rw------- 1 ehuang adjunct 20 Feb 2 18:23 test1 -rw------- 1 ehuang adjunct 20 Feb 2 18:23 test2 drwx--x--x 2 ehuang adjunct 512 Feb 2 18:23 ./
$ cp test1 test1.old
for rm (similarly for mv):
$ rm test1.old $ mkdir tmp $ ls -F faq.tar test1 test1.old test2 tmp/ $ rmdir tmp $ mv test1 test1.old
$ cat test2 "This is file test2 UNIX shell programming demo " $ more test2 $ less test2 $ pg test1 $ head test1 This is a new file called test1 and more ... $ tail test1
$ nl test2 > test2.nl $ cat test2.nl 1 This is file test2 2 UNIX shell programming demo
$ wc -l test1 3 lines "test1"
$ exit
$ diff test1 test1.old 2,3c2 < This is a new file called test1 < and more ... --- > This is file test1 $ comm test1 test2 This is a new file called test1 This is file test2 UNIX shell programming demo and more ...
$ man ls Reformatting page. Wait... done User Commands ls(1) NAME ls - list contents of directory SYNOPSIS /usr/bin/ls [ -aAbcCdfFgilLmnopqrRstux1 ] [ file... ] /usr/xpg4/bin/ls [ -aAbcCdfFgilLmnopqrRstux1 ] [ file... ] DESCRIPTION For each file that is a directory, ls lists the contents of the directory; for each file that is an ordinary file, ls repeats its name and any other information requested. The output is sorted alphabetically by default. When no argu- ment is given, the current directory is listed. When --More--(5%) $ man man Reformatting page. Wait... done User Commands man(1) NAME man - find and display reference manual pages SYNOPSIS man [ - ] [ -adFlrt ] [ -M path ] [ -T macro-package ] [-s section ] name ... man [ -M path ] -k keyword ... man [ -M path ] -f file ... DESCRIPTION -More--(5%)
$ compress faq.tar $ ls -l total 424 -rw------- 1 ehuang adjunct 201547 Jan 31 21:04 faq.tar.Z -rw------- 1 ehuang adjunct 46 Feb 2 18:47 test1 -rw------- 1 ehuang adjunct 20 Feb 2 18:33 test1.old -rw------- 1 ehuang adjunct 57 Feb 2 18:35 test2 drwx--x--x 2 ehuang adjunct 512 Feb 2 18:37 tmp/ $ uncompress faq.tar.Z $ ls -l total 936 -rw------- 1 ehuang adjunct 466944 Jan 31 21:04 faq.tar -rw------- 1 ehuang adjunct 46 Feb 2 18:47 test1 -rw------- 1 ehuang adjunct 20 Feb 2 18:33 test1.old -rw------- 1 ehuang adjunct 57 Feb 2 18:35 test2 drwx--x--x 2 ehuang adjunct 512 Feb 2 18:37 tmp/ $ gzip faq.tar $ ls -l total 360 -rw------- 1 ehuang adjunct 170070 Jan 31 21:04 faq.tar.gz -rw------- 1 ehuang adjunct 46 Feb 2 18:47 test1 -rw------- 1 ehuang adjunct 20 Feb 2 18:33 test1.old -rw------- 1 ehuang adjunct 57 Feb 2 18:35 test2 drwx--x--x 2 ehuang adjunct 512 Feb 2 18:37 tmp/ $ gunzip faq.tar.gz ( gzip/gunzip is better than compress/uncompress because it uses the better algorithm )
$ ps -al F UID PID PPID %C PRI NI SZ RSS WCHAN S TT TIME COMMAND 8 0 17111 17106 0 0 0 0 Z 0:00 8 0 17112 17106 0 0 0 0 Z 0:00 8 0 17117 17106 0 0 0 0 Z 0:00 8 0 17143 17106 0 0 0 0 Z 0:00 8 0 17170 17169 0 0 0 0 Z 0:00 8 0 7117 1 0 58 20 1432 572 modlinka S console 0:00 -ksh 8 196 1481 1478 0 48 20 1448 908 autofs_m S pts/7 0:00 -ksh
$ chmod 711 test1 $ chmod a+r test1
$ du 2 ./tmp 362 . $ df / (/dev/dsk/c0t3d0s0 ): 62700 blocks 24923 files /usr (/dev/dsk/c0t3d0s6 ): 181724 blocks 206193 files /opt (/dev/dsk/c0t3d0s7 ): 177874 blocks 154569 files /tmp (swap ): 485560 blocks 9793 files
$ lpq hp4si1_2 is ready and printing Rank Owner Job File(s) Total Size active jerry 5 asm.h 1672 bytes $ lpr test1 $ man lprm
$ cal 12 1999 December 1999 S M Tu W Th F S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
$ bc 2+5 7 15*19 285 quit
$ write [user] (use with care, do NOT interrupt others who are busy..) $ talk [user] (use with care, do NOT interrupt others who are busy working..)
$ pine An electronic mail program which is fairly easy to use. You can read about this in the computer lab help desk manual. We will not use too much time on this. There is also on-line manual available on Web.
Using Command mode ZZ - save file and exit :q! - exit without save :w - write buffer to disk h (left) j (down) k (up) l (right) ndw - delete n words (default for n = 1) nx - delete n characters (default for n = 1) ndd - delete n lines (default for n = 1) - - go to start of previous line ^ - go to first non-blank character of current line O - go to first column of current line $ - go to end of current line nG - go to nth line of file (default for n = 1) nyy - yank and save n lines p - put down lines saved Using INSERT MODE <esc> - exit INSERT mode i - enter INSERT mode ; insert to left of cursor a - enter INSERT mode ; insert to right of cursor A - enter INSERT mode ; add at end of current line o - enter INSERT mode ; add a new line after current line O - enter INSERT mode ; add a new line before current line /<pat> - search from cursor down for pattern <pat> ?<pat> - search from cursor up for pattern <pat> n - go to next occurrence of last pattern indicated N - go to previous occurrence of last pattern indicated
Example: stty erase '^h'
stty kill '^u'
stty intr '^c'
These are the typical settings. Note the differences from the defaults given by simply stty -a
intr = ^C; quit = ^\; erase = ^H; kill = ^U; eof = ^D; eol = ^@; susp = ^Z; stop = ^S; start = ^Q;