Unix Notes ########## Vi - some useful commands ========================= esc- enter command mode inserting text (exits command mode and enters edit mode) -------------- i - insert before cursor a - append after cursor o - start new line below cursor O - start new line above cursor deleting text (must be in command mode) ------------- x - delete character on cursor dd - delete current line dw - delete to end of word moving the cursor (must be in command mode) ----------------- h j k l - left, down, up, right ^F - forward one screen ^B - backward one screen ^D - down half a screen ^U - up half a screen w - forward on word b - backward on word 0 - move to beginning of line $ - move to end of line G - move to last line of file nG - move to nth line file commands (must be in command mode) ------------- :w - write (save) file :w! - write (save) file (force, and ignore permissions) :x - save and exit :q - quit :q! - quit without saving changes miscellaneous commands (must be in command mode) ---------------------- u - undo /pattern - search forward for pattern ?pattern - search backward for pattern :s/old/new/ - substitute new for old on current line (1st occurence only) :s/old/new/g - substitute new for old on current line (all occurences) :1,$s/old/new/g - substitute new for all occurences of old ============================================================================= ============================================================================= Some useful Unix commands ========================= ls -la - file listing of all files, in long format ls -t - file listing sorted by time stamp ls -F - file listing, puts a * for executables, @ for symbolic links, / for directories passwd - changes your password date - prints date and time mv /usr/people/john/file1 /usr/people/mary/file1 - move file1 to new location mv file1 file2 - rename file1 to file2 mkdir directory - make new directory cp file1 file2 - copy file1 to file2 rm file1 - remove a file1 rm -r directory - remove directory and all contents in it rmdir directory - removes an empty directory file filename - reports on type of file Permissions ----------- chmod guo+rwx filename chgrp newgroup filename chown newowner filename umask nnn - Don't allow the following - change default file permissions based on the following rules: for files, 666 for directories, 777 -nnn -nnn --- --- mmm ppp User Group Others Read 4 4 4 Write 2 2 2 eXecute 1 1 1 ------------- 7 7 7 screen control -------------- ^S - stop output from scrolling off screen ^Q - resume scrolling ^D - send EOF ^C - interupt (terminate) current process stty -a - list current terminal settings stty erase '^H' - assigns the erase command to Ctrl-H job control -- C-shell specific ------------------------------- prg & - run the prg in the background ^Z - stop current task bg - run stopped task in background fg - run stopped task in foreground jobs -l - list current processes envoked by the current shell bg %1 - run job #1 in the background fg %2 - run job #2 in the foreground kill %1 - kill job #1 C-Shell specific information ---------------------------- To customize your C-shell, edit the file ~/.cshrc env - prints environmental variables setenv VAR value - assigns value to variable VAR alias ls 'ls -F' - makes an alias command alias rm 'rm -i' - makes an alias command for interactive removals unalias ls - unalias the command echo Hello world - prints 'Hello world' to screen source script - read$interpret the script Pipe and filter --------------- e.g. ls | more ls -l | grep netscape ls | sort | more ls > filelisting.txt ls -l >> filelisting.txt ps | grep httpd > processlisting.txt ps elf | head -1 ; ps elf | grep httpd echo Hi there > message.txt ls -l 2> errfile.txt (not for C-shell) ls -l >& errfile.txt (use for C-shell, both err&std output) File searching -------------- find / -name filename -print find / -name "*filename*" -print > findresults.txt find / filename -user thomas -size +2000000 -print ^^^^^^^ size in blocks (1block=512bytes) find / filename -user thomas -size +1000000c -print ^^^^^^^^ size in characters (1char=1byte) find / filename -mtime n -print files time stamped less than n days ago -group groupname files belonging to a specific group -type d only directories -type f only files Creating symbolic links ----------------------- e.g. ln -s realfile fakefile Wild cards ---------- * matches any number of characters ? matches 1 character Text viewing programs --------------------- more filename - view contents of filename tail filename - view last 10 lines of filename tail -100 filename - view last 100 lines of filename tail -f filename - view last 10 lines of filename and follow any updates head filename - view first 10 lines of filename head -1 filename - view first line of filename cmp file1 file2 - compare file1 and file2 diff file1 file2 - compare files and report differences line by line ============================================================================= ============================================================================= Unix Administration =================== /etc/skel/ - skeleton files to be copied to a new user' directory /etc/passwd - password file /etc/group - group definition file finger user - finger user process management ------------------ services on NT called daemons on Unix ps -e - list all processes ps -el - long listing of all processes ps -ef - list process including path to executing process ps -u user - show processes running by user kill -HUP nnn - kill process nnn but do it nicely kill nnn - kill process nnn immediately df -k - list disk free space in bytes du -k - list disk usage in bytes tops - shows processes currently running on system uptime - shows how long the system has been running Software Management ------------------- versons -b - brief listing of installed programs inst - run software manager Tape archives ------------- tar tvf filename - list contents of tar file, verbose mode tar xvf filename - extract tar file, verbose mode tar cvf archive1.tar files - create tar file Gnu Zip ------- gzip filename - zip filename gunzip filename - unzip file name Nslookup -------- nslookup - name service lookup nslookup - 209.5.24.100 - name service lookup using the following name server While in nslookup: ls watco.ca list entries in watco.ca ls -a watco.ca list aliases in watco.ca ls -d watco.ca detailed listing of watco.ca Network utilities ----------------- ping ping www.watco.ca 100 10 - use 100 byte packets, send 10 of them traceroute www.watco.ca - trace packet route to www.watco.ca netstat -r - network card routing information netstat -C - netstat utility ifconfig -a - list interface config. for all network cards snoop - snoop on all packets Cron (file crontab) ---- Use it to automate tasks System startup -------------- on startup, reads /etc/inittab file 1. runs sysinit processes first 2. implements default state 3. executes scripts for appropriate states run states Directories ---------------------------------- 0 system shutdown /etc/rc0.d/ 1 single-user /etc/rc1.d/ 2 networking /etc/rc2.d/ 3 NFS /etc/rc3.d/ . 5 reboot(old PC) /etc/rc0.d/ 6 reboot /etc/rc0.d/ other directories and files --------------------------- /etc/init.d/ holds all startup-scripts /etc/shutdown for pre-SVR3 shutdown /etc/rc.d/ for pre-SVR3 startup Changing system states ---------------------- init n change to system state n Shutting down the system ------------------------ shutdown -g30 -i0 shutdown system, give 30sec grace, run state 0 Disk activity ------------- lost+found directory holding place after fsck is done Mounting a file system ---------------------- Manual: mount -t xfs -rw /dev/dsk/c0t3d0s7 /disk2 use umount to unmount automatically at boot time: add entry to /etc/fstab Networking info --------------- /etc/services file maps service to ports /etc/inet.conf file for inet daemon configuration