Function.s - A basic Unix hack guide - 05/09/05.00 Function.s is a quick guide to various Unix commands. Though mostly for Linux, 90% or more of these commands will work for ANY *NIX. ***************************************************************************** Desktop Enviroments ***************************************************************************** startx = Start a XFree86 X-windows enviroment [ Must be on the console ] window = install a window enviroment op= window enviroment; for Xenix Operating systems openwin = Start X-windows on Linux ***************************************************************************** On-line Help ***************************************************************************** whatis = Whatis [cmd] = To give help on given command; Xenix man = man [cmd] = to get instructions on any command ***************************************************************************** Command Shells ***************************************************************************** sh = enter the borne shell '$' csh = enter the 'c' shell '%' ksh = enter the 'k' Shell; '$' tcsh = enter the 'T' shell - a combination of the 'k' and 'c' shell bash = enter the BASH shell - the ultimate combo of the Ksh and csh shell su = superuser access - You need the ROOT password to gain access screen - run multiple virtual logins under one login splitvt - Run dual shells in one VT terminal session (much like TALK) [Linux] ***************************************************************************** File Maintenance ***************************************************************************** l = list of breif files; Xenix ll = most in-deapth listing of files in the current directory, date, chmod ls = Basic deapth dir; ls -al = find specific info on file lf = list directories and executable files etc lc = list a directory in colonm mode ln = ln [s,h] - Create virtual directories to other directories on the machine > 'ln -s /user/s/fabian/csci57 /user/s/dranch/csci57' unlink = to delete specific virtual links [ unlink ] cd [/dir] = to change into the specified directory pwd = get the current directory cp = copy files rcp = rcp file user@host - Copy a file to a remote server > 'rcp .profile cscihp:' This copies the local file .profile to the > to your account on the machine "cscihp" scp = similar to rcp but uses SSH to fully encrypt the traffic rm = delete files mv = move/rename files or directories [ mv < file or directory> ] copy = to copy contents of one directory to another touch = to create a empty dummy file rmdir = rmdir [directory] = remove a directory mkdir = mkdir [directory] = make a directory xcopy = full path to path copy utility ( cp can only do so much ) [Linux] find = to locate a specific file diff = to compare to files whereis = [cmd] = find the path to a specific command; du = du -m to display user's and general disk usage df = to determine free disk space ***************************************************************************** File compression / Archiving ***************************************************************************** bzip2 = BZIP2 compression (.bz2 extension) gzip/gunzip = GNU ZIP compression (.gz extension) compress = Compress a file ( .Z extension) [old.. use gzip] uncompress = [file] uncompress specified file tar = Unix standard archive tool compression/uncompression [ looks like 'filename.tar'] - Has a maximum file size limit of 2GB - Will instantly DIE if the archive as any ERRORs > tar and compress a directory: cd /some-dir; tar cvzf /tmp/newfile.tgz . > uncompress a directory: tar xzvf /tmp/newfile.tgz > copy a given directory to somewhere else: cd /some-directory; tar cf - . | (cd /some-other-dir; tar xvf -) cpio = Unix standard archive tool - No maximum file size limit - Can skip over files that have errors in the archive > create a archive of a directory: find /some-dir | cpio -ov -H crc > /tmp/newfile.cpio uuto = Unix to Unix file transfer ' uuto file.name user@system ' using UUCP (very old) > goes to the /usr/spool/uucppublic directory uupick = validate public files ***************************************************************************** File Permissions & system setup ***************************************************************************** chmod = chmod [gus] [+-] [rwx] [file] - Change access privledges on specific > files/dirs. chown = chown[user:group] file - Change the ownership of a given file to a given user and optionally, an given group chgrp = chgrp [group] [file/dir] - Change the group permissions o chacl = chacl user.% [+-=] [rwx] file - Allow other users access to a directory chacl = chacl "user.% -rwx" `tty` = Denies a specific user WRITE or re-direction writting to your tty. chsh = chsh [username] [shell] - to change the initial shell upon login chfn = chfn [username] - to change the stats / phone #s for the user stty = change the aspects of the current terminal configuration set = BASH - set local enviroment variables and general setup - running set by itself will display the entire setup setenv - KSH - set various environment varables - running setenv by itself will display the entire setup passwd = to change a password ***************************************************************************** Text Editors ***************************************************************************** textedit = Good X-windows based Linux text editor vi = Unix standard visual editor Vi operates in TWO modes: EDIT mode and COMMAND mode. All editing and related procedures are done in EDIT mode, where as all searches, file saving and reading, etc are done in the COMMAND mode. To enter the COMMAND mode, simply press the 'ESC' key Basic editor commands - These commands are given from the COMMAND mode to place the editor into the desired EDITing mode. NOTE: the following commands are CASE sensitive.. 'i' = insert text 'I' = insert text in previous line 'r' = replace text 'R' = insert one character 'o' = insert new line below cursor 'O' = insert new line above cursor 'x' = delete one character 'dd' = delete one line 'd#d' = delete # of line(s) 'dw' = delete one word 'd#w' = delete # of word(s) Undo Commands 'u' = Undo last keystroke 'U' = Resore current line to orginal state Movement commands 'b' = Goto previous word 'w' = Goto next word '^' = Goto the beginning of line '0' = Goto the beginning of the column '^f' = Page Down ( In command mode ) '^b' = Page Up ( In command mode ) '1G' = First line in file 'G' = Last line in fil Cut / Paste commands '%yy' = Yank '%' number of lines onto the clipboard 'p' = Put clipboard after cursor 'P' = Put clipboard before cursor Search / Replace '/xxx ' = Forward Search for 'xxx' text string '?xxx ' = Reverse search for 'xxx' text string '/xxx/yyy[/g/c] ' = Search for xxx and replace with yyy = use /g for global changes = use /c for confirm globally search forwards / string search / command -------------------------------------------------- ':g/^V^M/d' = forward find and delete all LINES that have ^M (carriage returns) in a text file or ':g/^V^M/s///g' = forward find and delete all ^M (carriage returns) CHARACTERS in a text file or -- first line to last line SEARCH / search string / replace string / globally ----------------------------------------------------------------------- ':1,$s/^V^M//g' = forward find and delete all ^M (carriage returns) CHARACTERS in a text file globally search forwards / NOT string search / command -------------------------------------------------- ':v/^V^M/s///g' = find and delete ALL lines NOT containing ^M (carriage returns) in a text file Misc commands '^g ' = Print # of lines, file name, and percent '=' = Print number of lines in file '.=' = Print line number Save / Exit While in the ESCAPE mode, by hitting a ':', you will see the ":" in the lower left corner of your screen. This tells Vi to prepare for an escape command. ':x' = to exit and save changes) ':w' = Save but don't exit ':q!' = to exit but not save changes Note: When using Vi, do not use the cursor keys to move around while in EDIT mode. You must first enter the COMMAND mode then use the cursor keys else Vi might go nuts and change your document in un-desirable ways! ******************************** Emacs = An advanced unix text editor [ not very common ] 'Ctrl-x Ctrl-r' = read a file " 'Ctrl-s' = save a file " 'Ctrl-w' = save-as-file " 'Ctrl-d' = delete line " 'Ctrl-!' = shell to unix " 'Cntl-z' = to suspend editing " 'Ctrl-c' = Exit Emacs ***************************************************************************** Display Formatters ***************************************************************************** cat = Display a given text file - much like TYPE of Ms-Dos zcat = [file] {options} = compress/decompress file [ looks like 'filename.Z'] more = to display a file one screen at a time less = like 'more' but more complex and easier to use > 'cat myphonenumbers.txt | grep '822-' zless = View GZiped text files with Less wc = tells how many lines words etc. who | wc -l head = display first line of a file tail = display last line of a file col = remove all escape sequences in a file ***************************************************************************** Picture Viewers ***************************************************************************** Xgif = Xgif [filename] to display a GIF file under X-Windows xv = Picture viewer for X-terminals ***************************************************************************** Printer Commands ***************************************************************************** lp [file] = send the given file to the line printer cansel = to stop a current lp job 'cansel laser-245' lpstat = get the current status of a printer {options} > -o = to show all printing in queue ***************************************************************************** System and hardware information ***************************************************************************** dmesg = displays all the system bootup info including all hardware details ***************************************************************************** System Users & Network connection info ***************************************************************************** w = people logged and there processes who = who is on the local machine whois [user] = more verbose info on a specific user uts = like 'who' but more verbose form ruptime [host]= show stats on remote systems rwho [host]= who is on remote machines u = just users names online ftpwho = Who is using FTP services (linux) finger [user] [@domain] = to tell specifics of user > -m = gives specifics on the given user > 'finger @corpse.csuchico.edu' will show all users on CORPSe from any Unix > machine logname = who is the current user lastlogin [user] = to give the username of the last user on-line and their tty nslookup = nslookup [host] - to determine the IP address of a given host - host / dig - get additional host info via DNS netstat = get detailed and techincal info on the network's status > try using "netstat -an" lsof = get very detaiuled info on network daemons, port ports, etc. > try using "lsof -N -i -p" fuser = Find out what processes are blocking the umount of a given file system ***************************************************************************** Process Manipulation ***************************************************************************** ps = a list of your current process top = a list of processes running from lasrgest to smallest : updated real time kill = to kill a hung or stray process killall = to kill one or more processes by name skill = Kill a group of processes tload = displays a real-time text-based load monitor [Linux] xload = displays a real-time X-windows load monitor at = at [time] day] = run a specific command at a specific time nice = to recongifure a process's priority (as in no priority!) snice = RE-prioritize a group of processes ^Z = Will stop your current process and return a process number > when you stop a process this way, this process is stopped process ID #1 > The next process you stop this way will get stopped process ID #2 ^T = Tell UNIX to respond to see if the system has hung fg %# = Bring to the forground a specific stopped process 'fg %1' bg %# = Place a stopped process into a background processing state 'bg %1' meminfo = Nice X-window program showing free memory and sys load [Linux] nohup = execute a command imune to HUPs with an increased priority pstree = Display running process in a tree format showing dependancies [Linux] ***************************************************************************** User specific files ***************************************************************************** $home = enviroment variable containing the user's home directory > 'cd $home' will place you in your root directory .profile = BASH and KSH - where all of the user profile is - Much like a DOS machine's AUTOEXEC.BAT .login = Similar to the .profile file but loaded FIRST .plan = text file displayed when a user FINGERs your login ID .cshrc = the setup file for a C shell [ like the autoexec.bat ] .exrc = resource setup file for the EX and VI editors .signature = file resource for appending a footer (signature) to all e-mails ***************************************************************************** Remote Host Communication ***************************************************************************** ssh - to log into various remote systems SECURELY > ie. ssh dranch@liz.ecst.csuchico.edu - All communications are fully encrypted - SSH is a 100% replacement for TELNET but is secure sftp - file transfer to remote systems SECURELY > ie. sftp liz.ecst.csuchico.edu - SFTP is a 100% replacement for FTP but is secure - See below telnet = to log into various remote systems > ie. telnet liz.ecst.csuchico.edu - All communications are transmitted in clear text rlogin = rlogin [address] = logon to a remote host; similar to TELNET - All communications are transmitted in clear text - Uses insecure authentication methods ftp = to tranfer files only between mainframes - All communications are transmitted in clear text > open [host]= to initalize a link; ie. 'open liz.ecst.csuchico.edu' > binary = set ftp to tranfer binary files. MUST be set for ANY binary file > asc = set ftp to tranfer in ascii mode > user = will create a new login for that system if you have a password > get = to download a file to your local system > mget = to download files in batch to local system > put = to upload file(s) to the remote system from local system > mput = to upload multiple files in batch > prompt = turn off the file confirmation > close = to disconnect from the remote mainframe > bye = to exit FTP NOTE: once a connection is established, if you don't have passowrd at the given HOST, you might be able to logon ANONYMOUSLY. Once FTP connects to the remote host, follow these steps: At the 'login:' prompt, type 'anonymous' At the 'password:' prompt, type '@' > Some FTP sites have CHATTING going on within directories... > to add to the conversation, use 'send | " ------ "' for your message > to remove your new file conversation, use 'del ---' where the --- > is the beginning of your message ***************************************************************************** User Communication ***************************************************************************** talk = talk [user@domain] = visual chat system > the tty command is used when you wish to talk to a specific tty # > 'talk dranch@corpse.ecst.csuchico.edu' ytalk = Just like TALK but allows multiple users mesg [y/n] = turn on/off users access to directly write to your screen > this will allow/deny users to 'talk' with you write = write [user] [tty] = send a message to a user anytime hello = hello (user) much like write tin = to read new news written by the sys admin about system specific info - trn, pine, news, etc. are other news readers pine = A nice GUI'ish text email and News reader with address books, etc. mutt = A very powerful text email system elm = elm [user@domain] = Visual e-mail system [ uses Vi as its editor mailx = More intelligent version of mail > 'mailx dranch@corpse.ecst.csuchico < function.s' sends me the specific > file 'function.s' mail = to send someone mail ' mail [login] ' bitchx / ircii / irc > Multichannel talk/chat application > /list - get a list of all available channels > /join #channel - Join a specific channel - You must prefix the "#" > /list #linux* - get a list of all #linux channels > /leave #channel note - exit the channel leaving a little note > /quit - quit IRC > Some good IRC servers: irc1.cerf.net port 6667 > irc.law.emory.edu port 6667 Getting an anonymous e-mail site re-direction: send e-mail to 'nick@anon.penet.fi' with your desired alias > ie. Butthead in the the subject field. The remote system will mail you > back with your new anonymous address and when anyone sends you mail at > that site, it will automatically be forwarded to your normal mailing > address. ***************************************************************************** System I/O Protocals ***************************************************************************** minicom = A "Telix" like DOS modem / serial port control program cu = a command to access the modem directly kermit = to u/l and d/l files xmodem = to u/l and d/l files sz = sz [file] = Send specified file in ZMODEM > -a converts UNIX-type text files into PC-type text files > -b sends the desired file via binary ( no converting or altering ) rz = rz [file] = Receive specified file in ZMODEM > -a converts PC carriage returns to UNIX returns > -b sends the desired file via binary ( no converting or altering ) ***************************************************************************** System DISK Formatting ***************************************************************************** format /dev/rfd096ds15 for a 1.2M, format /dev/rfd096ds9 for a 720K format /dev/rctmini = to format a tape superformat = Format floppies to high capacities [Linux] ***************************************************************************** Misc. System Commands ***************************************************************************** lastcomm = display users last commands used in reverse order date = to display a date cal = a calender fortune = to get a fortune cookie banner = Create large text [Create horizontal print banners for Linux] sysvbanner = Create large text [Linux] ***************************************************************************** Advanced System Commands ***************************************************************************** strings = Find readable text in a executable file - excellent for finding command-line options strace program = traces a program as it runs to help troubleshoot program problems, etc. shutdown [-r | -h] now = shutdown and either REBOOT or POWER-OFF the machine haltsys = to terminate the machine: Xenix enable [tty] = to enable specific tty port disable [tty] = to disable a specific tty port lock = to reserve a terminal ***************************************************************************** Programming Language Compliers ***************************************************************************** cc = [*.c] = C compiler pc = [*.p] = pascal compile > -o = rename the complied code to specified file > -L = Outputs compile errors to specific file pmake - Maintain a C/C++ program's dependancies ***************************************************************************** System Syntax ***************************************************************************** \ = to continue a command line on another line ; = to do multiple commands per line ';' > = to redirect an output >> = to add onto the end of another file < = input redirection | = to use the output of one command as the input of another = '|' *pipe* ! = to shell into the borne shell at times of in 'op' & = to execute a process in the background ***************************************************************************** System Specific Commands ***************************************************************************** Linux: ------ -Video/Terminal related reset - if the size of the screen get hosed, run this resizecons - if the console COLUMN size gets hosed, run this restorepalette - if the screen's palette gets hosed, run this. xtune - to get the most from the Xwindows display xwininfo - find out info/coordinates on a Xwindow Hp-UX: ------ SAM - Hp's Graphical system administration tool Sun Solaris: ------------ bootprom mode: probe-ide - shows IDE devices probe-scsi - shows SCSI devices To reboot the machine: - From the HD: "boot -r" - From the CD-ROM: "boot cdrom" boot cdrom -s = boot off a Solaris install CDROM for recovery printenv boot-device = get the default boot device setenv boot-device disk = set the default to Slice0 on the first disk Drive layouts look like: /dev/dsk/c0t0d0s7 Getting CPU info prtconf = displays system info psrinfo -v = displays CPU info prtconf -vp = displays CPU and all PCI info psrset -e processor_set command args = assign a process to a specific CPU Assigning process priority within a given scheduling class: nice or renice Assigning a process to a different scheduling class priocntl (read the man page for specifics) Configuring the Network Adding Ethernet cards ifconfig eri0 plumb (also qfe, hme, ge, ce, etc.) Setting the hostname after a sys-unconfig hostname "non-FQDN-hostname" echo "non-FQDN-hostname" > /etc/nodename Setting the IP address of the various interfaces echo "192.168.0.10" > /etc/hostname.hme0 echo "192.168.10.10" > /etc/hostname.ge0 Setting the netmasks for non-classful networks echo "192.168.65.0 255.255.248.0" > /etc/inet/netmasks Setting the domain: echo "mynet.com" > /etc/defaultdomain Setting the default gateway echo "192.168.0.1" > /etc/defaultrouter bringing up NIS/Autofs: 1. Add the NIS servers to /etc/hosts 2. cp /etc/nsswitch.nis /etc/nsswitch.conf 3. "domainname xyz" where "xyz" is the NIS domain 4. "ypinit -c" and enter in the NIS servers by NAME and not by IP 5. /usr/lib/netsvc/yp/ypbind 6. ypwhich 7. restart "rpc" and "autofs" 8. Copy all /etc/auto* files from NIS servers to /etc Admintool - Solaris's graphical system administration tool To re-configure the machine: "sys-unconfig" from within Solaris To bring the machine down to a boot "OK" prompt: "init 0" If the machine has completely crashed, " + A" will bring the machine to a boot prompt. [Note: this can damage your partitioning] -- FOR WYSE-60 TERMINALS to lock = echo "\033#" > \dev\tty{} to unlock = echo "\033\"" > \dev\tty{} to beep = echo "\033^g" > /dev/tty{} to reverse = echo "\033^1" > /dev/tty{} to unreverse = echo "\033^0" > /dev/tty{} screen display off = echo "\033'8" > /dev/tty{} screen display on = echo "\033'9" > /dev/tty{} select aux port = echo "\033e9" > /dev/tty{} select modem port = echo "\033e8" > /dev/tty{} to logout = use 'exit' or 'logout' = exit > /dev/tty{} ***************************************************************************** InterNET specific information ***************************************************************************** To be placed on the mailing list for the InterNET resource guide list ( this is the LIST-of-LISTs for all the InterNET services such as library catalogs, various databases, etc) send mail to 'resource-guide-request@nnsc.nsf.net' To access all the FAQs ( Frequently Asked Questions on any topic ), RTF's, etc on the net, anonymously FTP to 'ftp.nisc.sri.com' or call 1(800)235-3155 for voice help. To publish yourself in the WHOIS database ( so people can always find you on the InterNET), anonymously ftp to rs.internic.net and in the /templates dir, get the user-template.txt file. Fill this out and send it to admin@ds.internic.net. Your Information will be inserted into the international whitepages database. To search the library of Congress for specif c info - Telnet dra.com To download satelite data - telnet nssdca.gsfc.nasa.gov Errata: -------- 05/09/05 - Added some more Vi search/replace examples 01/25/05 - Added Solaris commands to get PCI info 10/13/04 - Added Solaris CPU commands "psr" and manually configuring the network config files if sys-unconfig cores on you 04/22/04 - Added Solaris ifconfig commands 09/30/02 - Added some Solaris commands 12/29/01 - Updated to reflect some Solaris commands; added SSH commands; added minicom, strace, screen, tin/trn, pine, mutt, lsof. etc. 01/25/00 end.