Use the SUN Operating System : 1. Work Session. ( "%" is means C-shell.) (1). Login. login : _______ password : _______ ( If you are first login , it will not show.) (2). Set or change password on Sun workstations. % passwd Changing password for user. Old password: ______ ( If you are first login , it will not show.) New password: ______ Retype new password: ______ (3). Logout. a. Type the following to logout % logout or % exit or % CTRL D b. Problems logging out #System say: There are stopped jobs -->Solution: Type "logout" two or three times #System say: Not login shell -->Solution: Type "exit", then type "logout" 2. Online Manual Page. % man intro ( Introduction to SUN OS's command.) % man command-name 3. Informative Command : (1).Display the pathname of the current working directory. % pwd : print working directory name (2).Display users logging in. %who : who is logged in on the system %whoami : display the effective current username %w : who is logged in, and what are they doing (3).Display the architecture %arch : display the architecture of the current host %arch -k : display the kernel architecture .Current Architectures Application Kernel Current Sun Architecture Architecture System Models =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= sun3 sun3 3/50, 3/60, 3/75, 3/110, 3/140, 3/160, 3/180, 3/260, 3/280 sun3 sun3x 3/80, 3/460, 3/470, 3/480 sun4 sun4 4/110, 4/260, 4/280, SPARCsystem 300 series, SPARCsystem 400 series sun4 sun4c SPARCsystem 1, SPARCsystem 1+, SPARCsystem 2, SPARCsystem IPC, SPARCsystem SLC sun4 sun4m SPARCsystem 600MP series sun386 sun386 386i/150, 386i/250 4. File Related Command : (1). List the contents of a directory. % ls [-aAlgrRFctu] : for listing of current directory. % ls filename : for listing of a single file. % ls directory-name : for listing of another directory. Options : -a List all entries; in the absence of this option,entries whose names begin with a `.' are not listed. -A Same as -a, except that `.' and `..' are not listed. -l List in long format, giving mode, number of links, owner, size in bytes,and time of last modification for each file. -g For ls, show the group ownership of the file in a long output. -r Reverse the order of sort to get reverse alphabetic or oldest first as appropriate. -R Recursively list subdirectories encountered. -F Mark directories with a trailing slash (`/'),executable files with a trailing asterisk (`*'),symbolic links with a trailing at-sign (`@'), and AF_UNIX address family sockets with a trailing equals sign (`='). -c Use time of last edit (or last mode change) for sorting or printing. -t Sort by time modified (latest first) instead of by name. -u Use time of last access instead of last modification for sorting (with the -t option) and/or printing (with the -l option). EXAMPLES : (ntucsa) tst# ls bin etc kadb mnt sys usr boot export lib pcfs tftpboot var dev home lost+found sbin tmp vmunix (ntucsa) tst# ls -l total 2307 lrwxrwxrwx 1 root 7 Mar 23 1993 bin -> usr/bin -r--r--r-- 1 root 103544 Mar 23 1993 boot drwxr-sr-x 2 root 11264 Oct 6 17:30 dev drwxr-sr-x 7 root 2048 Oct 6 17:30 etc drwxr-sr-x 4 root 512 Mar 23 1993 export drwxr-xr-x 4 root 512 Sep 27 16:31 home -rwxr-xr-x 1 root 248666 Mar 23 1993 kadb lrwxrwxrwx 1 root 7 Mar 23 1993 lib -> usr/lib drwxr-xr-x 2 root 8192 Mar 23 1993 lost+found drwxr-sr-x 2 root 512 Mar 23 1993 mnt drwxr-sr-x 2 root 512 Mar 23 1993 pcfs drwxr-sr-x 2 root 512 Mar 23 1993 sbin lrwxrwxrwx 1 root 13 Mar 23 1993 sys -> ./usr/kvm/sys drwxr-sr-x 2 root 512 Mar 23 1993 tftpboot drwxrwsrwt 4 root 2560 Oct 7 04:16 tmp drwxr-sr-x 32 root 1024 Sep 29 18:57 usr drwxr-sr-x 10 root 512 Sep 27 16:31 var -rwxr-xr-x 1 root 1936452 Sep 27 10:12 vmunix (ntucsa) tst# ls var adm crash log net preserve spool tmp yp (ntucsa) tst# (2). File Attributes (ntucsa) tst# ls -gl ~ drwxr-x--- 2 tst TA 512 Aug 8 17:13 Mail drwxr-x--- 3 tst TA 512 Sep 1 07:30 News ....... Each line contains a list of data about each filename,separated into several fields.Taking these fields in order from left to right, the fields are: * File Modes * Link Count * Owner Name * Group Name * File Size * Date/Time Last Modified * File Name (3).Change the permission mode of file or directory The chmod (change mode) command has 2 forms,absolute and symbolic In the absolute mode, the permissions are changed by issuing an octal number,the value of which specifies the permissions to be changed. % chmod [-fR] Mode filename ( or directory ) Modes : an octal number constructed from the OR of the following modes. 400 Read by owner. 200 Write by owner. 100 Execute (search in directory) by owner. 040 Read by group. 020 Write by group. 010 Execute (search) by group. 004 Read by others. 002 Write by others. 001 Execute (search) by others. 4000 Set user ID on execution. 2000 Set group ID on execution (this bit is ignored if the file is a directory; it may be set or cleared only using symbolic mode). 1000 Sticky bit. Options : -f Force.chmod will not complain if it fails to change the mode of a file. -R Recursively descend through directory arguments,setting the mode for each file as described above. When symbolic links are encountered,their mode is notchanged and they are not traversed. EXAMPLES : (ntucsb) tst# cd / (ntucsb) tst# chmod 777 ~ (ntucsb) tst# cd ~/.. (ntucsb) tst# ls -dl ~ drwxrwxrwx 7 tst 1024 Oct 6 09:43 /usr/master/tst/ (ntucsb) tst# chmod 700 ~ (ntucsb) tst# !-2 ls -dl ~ drwx------ 7 tst 1024 Oct 6 09:43 /usr/master/tst/ (ntucsb) tst# In symbolic form, chmod uses initials to indicate how the permissions can be changed. The initials are as following : u user(owner) g group o others a all r read access w write access x excute access EXAMPLES : (ntucsb) tst# ls -dl ~ drwx------ 7 tst 1024 Oct 6 09:43 /usr/master/tst/ (ntucsb) tst# chmod g+r,g+x ~ (ntucsb) tst# !ls ls -dl ~ drwxr-x--- 7 tst 1024 Oct 6 09:43 /usr/master/tst/ (ntucsb) tst# chmod a=r+x ~ (ntucsb) tst# !ls ls -dl ~ dr-xr-xr-x 7 tst 1024 Oct 6 09:43 /usr/master/tst/ (ntucsb) tst# (4). Change working directory. % cd : change directory to your home directory. % cd ~username : change directory to another user's home directory. % cd directory-name : change directory to another directory. % pushd . : push current directory into dir stack % popd : pop last entry of dir stack EXAMPLES: (ntucsa) tst# pwd / (ntucsa) tst# cd (ntucsa) tst# pwd /usr/master/tst (ntucsa) tst# cd ~rhc /usr/faculty/rhc: Permission denied (ntucsa) tst# cd /var/spool/cron (ntucsa) tst# pushd . /var/spool/cron /var/spool/cron (ntucsa) tst# cd ~/News (ntucsa) tst# pwd /usr/master/tst/News (ntucsa) tst# popd /var/spool/cron (ntucsa) tst# pwd /var/spool/cron (ntucsa) tst# (5). Display a text file content. % cat filename : catenate(link) and display a file % cat file1 file2 > file3 (6). Browse or page through a text file content. % more filename % page filename % cat filename | more % cat filename | more (7). Creat a new file. % cat > filename ... ... ( contents of new file ) ... CTRL D ( End of file ) (8). Creat a new directory. % mkdir directory-name (9). Move ( or Rename ) file or directory. % mv source-filename destination-filename : rename a file. % mv source-filename destination-directory : move a file into another directory. % mv source-directory destination-directory : rename a directory or move a directory into another directory. (10). Copy file. % cp source-filename destination-filename : copy a file into an- other filename. % cp source-filename destination-directory : copy a file into an- other directory. (11). Remove ( Delete ) file or directory. % rm filename : remove a file. % rmdir directory : remove an empty directory. % rm -r directory : remove a directory and its contents. (12).Change modification time. % touch filename ( or directory ) (13).Making links to files. % ln -s oldname newname : Make symbolic link to files. % ln oldname newname : Make hard link to files. (14).Editing files. % vi filename : visual display editor. Esc : set into command mode. * Set line number : :set nu : show line number. :set nonu : hide line number. * Insert characters and lines : a : insert characters to right of cursor. A : insert characters to right of cursor,at end of line. i : insert characters to left of cursor. I : insert characters to left of cursor,at beginning of line. o : insert line below cursor. O : insert line above cursor. * Insert a file into current file : :r filename : insert ( read ) file after cursor. :30 r filename : insert ( read ) file after cursor. * Save file and quit vi command : :w : save changes.( write buffer ) :wq : save change and quit vi. :x : save change and quit vi. ZZ : save change and quit vi. :w filename : write buffer to filename. :q! : quit without saving changes * Move cursor : h : move left. l : move right. j : move down. k : move up. w : move cursor to the right a word. W : move right one series-characters. b : move cursor to the left a word. B : move left one series-characters. H : move cursor to top of screen. M : move cursor to middle of screen. L : move cursor to bottom of screen. CTRL F : Backward scroll one screen. CTRL D : Backward scroll half screen. CTRL B : Forward scroll one screen. CTRL U : Forward scroll half screen. Return : move cursor down to next line top. BackSpace : move the cursor left. Space Bar : move the cursor right. * Clear the screen : CTRL L : clear scrambled screen * Move and copy : yy : yank or copy line. Y : yank or copy line. p : put yankes or deleted line below current line. P : put yankes or deleted line above current line. :1,2 co 10 : copy lines 1~2 and put after line 10. :3,4 m 20 : move lines 3~4 and put after line 20. * Delete : x : delete character. dw : delete word. dd : delete one line. D : delete cursor to line tail. :5,10 d : delete lines 5 to 10. * Find a line : G : go to last line of file. 20G : go to line 21 * Search and replace : /string/ : search for string. ?string? : search backward for string. n : find next ( or previous ) occurrence of string. :g/search-string/s//replace-string/gc : search and replace,consult at each occurence. :s/search-string/replace-string/g : search and replace. :1,$s/search-string/replace-string/g : search and replace,consult at each occurence. (15).Search file and string % find [path] -name [filename] -print % grep search-string filename (16).Print file % lpr filename (17).List the printer queue % lpq (18).Remove your printer job % lprm - or % lprm username or % lprm job-number (19).Selecting a printer % lpr -P[printer] filename % lpq -P[printer] % lprm -P[printer] job-number [printer] : printer name (20).Clear the terminal screen. % clear_colormap % clear (21).Directory abbreviation ~ : Home directory ~username : Another user's home directory . : Current Working directory .. : Parent of working directory (22).Pathname Simple : One filename or directory name to access local file or directory. Absolute : List of directory names from root directory (first /) to desired filename or directory name, each name separated by /. Relative : List of directory names from current position to desired filename or directory name,each name separated by /. (23).Wild cards ? : Single character wild card. * : Arbitray number of characters. 5. Find the pathname of a command or file : % whereis command : display the pathname of command. % which command : display the pathname of command and your alias. % whatis command : display a one-line summary about command. % find search-pathname -name filename -print : serach filename's path. 6. Search string : % grep search-string filename : search a file for a string. 7. Display line-by-line differences between pairs of files : % diff left-file right-file 8. I/O Redirecting and pipes : < : Standard input. > : Send output to named file. >! : Same, overwrite file if it exists. >& : Send standard error to file. >> : Append output to file. >>! : Same, overwrite file if it exists. >>& : Append standard error to file. | : Pipe output to named command ( filter ). |& : Include standard error in pipe. 9. C-shell features : (1). History substution : % set history=n : setup history list table length. % history : see history list. (2). Event designators : % !! : repreat previous command. % !!:p : display previous command. % !5 : command line 5 in history list table. % !string : command beginning with string. % !* : all arguments to previous command. % !$ : last arguments to previous command. % !^ : First arguments to previous command. % !:n : n'th argument. % ^^ : substitute portion of previous command line between symbols for new string after symbols (3). Alias : % alias : display the alias name of all commands which you define. % alias name 'command line' : assign command line to the alias name. (4). Unalias : % unalias name : discard aliases that match name. % unalias * : remove all aliases. (5). Variable Substitution : % set : display the values for all shell variables. % set var=value : assign a value to shell variable. % unset var : remove the values for a shell variable. % echo $var : display the value of shell variable. % setenv : display all environment variables. % setenv NAME word : set environment variable NAME to the value word. % unsetenv variable: remove variable from the environment. 10. Tape archive : Note : The device-name is the device name of tape driver. Example : QIC tape driver : ----> /dev/rst8 or /dev/nrst8 8mm tape driver : ----> /dev/rst1 or /dev/nrst1 And the device name can be a tarfile. (1). Creat tape archive. % tar cvf device-name filename ( or directory ) (2). List the table of contents of tape. % tar tvf device-name (3). Extract file or directory from tape. % tar xvf device-name (4). Write the named files on the end of the tarfile. Note : this option doesn't work with quarter-inch archive tape. % tar rvf tar-file filename ( or directory ) (5). Tape control. % mt -f /dev/nrst8 rewind : rewind the tape. % mt -f /dev/nrst8 fsf n : forward space over n count EOF marks. % mt -f /dev/nrst8 bsf n : back space over n count EOF marks. % mt -f /dev/nrst8 weof : write count EOF marks at the current position on the tape. 11. Use the floppy diskette : (1). Formatted the floppy diskette. % fdformat (2). Backup file or directory to floppy diskette. % bar cvf /dev/rfd0 file-name [ or directory ] ( If your data large than one floppy diskette size, it will automatically ejected, and show you request an additional diskette. And you must write the volume number on this diskette's label. ) % bar tvf /dev/rfd0 ( List the file or directory from diskette.) % bar xvf /dev/rfd0 ( Extract the file or directory from diskette.) % tar cvf /dev/rfd0c file-name [ or directory ] ( This command only can write the size is small or equal to the diskette's size ) % tar tvf /dev/rfd0c ( List the file or directory from diskette.) % tar xvf /dev/rfd0c ( Extract the file or directory from diskette.) (3). Eject floppy diskette. % eject (4) Current Usage : % /dosopen % cd /pcfs ... % cd % /dosclose % mdir a: : For more details , type "man mtools" % mcopy filename a: % mtype a:filename % eject 12. Job control : % command-line & : run command in background. % command-line Control Z : stop foreground job. % bg : place the current stop foreground job into background. % jobs : list of background jobs. % kill % : terminate current background job. 13. Process : % ps : listing your process. % ps -aux | grep username % kill -9 PID : terminate your PID's process. % at time script : execute a command or script at a specified time. 14. Control Key : KEY APPEARANCE FUNCTION ---------------------------------------------------------------------- ^U Erase entire command line ^W Erase last word on command line ^C Interrupts many program and shell scripts ^Z Suspends many program and shell scripts invisible Stops output of running program invisible Resumes output from program stopped by ^D End-of-file character used for logout; also terminates file input 15. Miscellaneous: % date : find the current date and time associated with your geographics location % date -u : date command with option for universal time (GMT) % cal 1993 : construct a calendar for the whole year of 1993 % cal 10 1993 : construct a monthly calendar (Oct. 93) % bc : (interactive program) basic calculator program 3 + 7 : To quit; type on next line 10 % spell filename : check spelling of words in specified file and type possible misspelling out to screen, unless you redirect the output to a file