----> UNIX Guide II <---- --> Rev. 5 <-- Chris Alfeld - calfeld@east.slc.k12.ut.us Legal Guck: You are free to distribute this guide unmodified in any non-profit way. If you would like to modify it, or distribute it for a profit (CD-ROM, etc..). Please ask me (address above). Archives: ftp://ftp.east.slc.k12.ut.us/calfeld/ http://www.math.utah.edu/creations/ gopher://gopher.east.slc.k12.ut.us/1/Guides/ ---------------------------------------------------------------------- - This Guide - This guide is designed to apply to most BSD Unix systems. It includes standard commands, plus several useful and common commands. - Notes - Mail programs: Almost all unix systems have 'mail' but most have replaced it with something. As such I will not have any mail programs. Compilers: Compilers are not used by the common unix user, and if you know how to program you won't need me to tell you how to access the compilers. Shell: I do not say anything about pipeing, redirection, or any other shell uses of programs (don't worry if you don't understand this) - Format - All command description will be in this format. - Syntax: Useful Flags: - Syntax - Anything surrounded by <> (i.e. ) is a variable expression (it should be replaced with something). Anything surrounded by [] (i.e. []) is optional (you don't need to have it to work). These are only for common uses. Almost all commands can be used with no arguments. - Contents - 1. The File System. A: Manipulating Files/Directories B: Displaying Files C: Editing Files 2. The Internet. A: Files B: Reaching out 3. System. A: Getting info on the system. B: Getting help C: Manipulating the system. - The Commands - 1. the File System A. Manipulating Files and Directories cd - change directory Syntax: cd [] cd will change your current directory to a directory specified in the command argument. can be absolute (cd /var), or relative (cd notes). can also use the '~' character either to change to your home directory (cd ~) or someone else home directory (cd ~). cd with no arguments will change to your home directory and is identical in function to 'cd ~'. ls - list directory contents Syntax: ls [flags] [] ls will list the contents of a directory. ls by itself will list the current directory. You can specify a list of a directories and/or files to list as well as several flags to control how the display appears. Wild cards can be used. Common wild cards are: * - match anything 0 or more characters long ? - match one character [x-y] - match any 1 character between x and y (i.e. [a-z] [abc] - match abs (i.e. [agh]) (can be longed then 3 i.e. [abdteh]) [combination of above] - i.e. [adeA-Zhu-z] Common Flags: -a - list all files including ., .. and all those beginning with a '.' (Files beginning with a . are normally not shown). -s - show size of files -l - show owner, permissions, size, group, etc.. of file -C - show in columns -F - append * to executables, / to directories, @ for links, etc. -t - sort in reverse order by time. mkdir - Make a directory. Syntax: mkdir mkdir will make 1 or more directories. rmdir - Removes a directory. Syntax: rmdir rm - Remove files. Syntax: rm [] rm main purpose is to remove files. It will also take flags that will allow it to remove directories. Wild cards are allowed as well. Common Flags: -r - remove listed files and directories plus all files in those directories plus all sub-dirs and there files in listed directories, etc.. -f - don't ask if you want to remove a file. -i - ask before removing a file. cp - copy files Syntax: cp [-r] cp will copy one or more files either to a new file or into a directory. All command line elements not not beginning with a - except the last one are the files to be copied, and the last element is where or what to copy them to. Flag: -r - copy directories as well as files mv - move files Syntax: mv mv < new name > This is basically the same as cp only it does not leave a copy of the file, does not need the -r flag for directories and is a lot faster then cp. ln - Make a link to a file. Syntax: ln -s Linking is to some a hard concept. Mac System 7 users will do best thinking of a link as an alias. Basically a link creates a file that points to the other file specified. So if you edit the link unix edits the file, etc... The -s flag is almost always used. What happens when it is not used is too complicated to put into this guide. file - display what type of file a file is. Syntax: file file displays guesses at what a file is. B. Displaying Files cat - basic file display command Syntax: cat cat simply displays the files to the screen without pause. more, page - Display file one page at a time. Syntax: page page and more are nearly identical programs that display a file one page at a time. Both function basically by using space bar to go forward one page and return to go forward one line. less - Display a file one page at a time with backwards and forwards movement. Syntax: less less is much like page. The main difference is that you can go back one line or forward one line with a single key allowing easy scrolling. To get help on less type 'h' while running it. C. Editing Files vi - File Editor Syntax: vi I dislike vi so won't do anything here except to mention that it exists and that it is on almost all systems. emacs - Powerful file editor and more Syntax: emacs [] [] emacs is far too complicated for me to explain here. It is an incredible file editor, a lisp compiler, and far more. To learn the basics of emacs type 'control-h t' to enter the tutorial. emacs can be extited with ^X^C (control-X control-C) pico - simple text editor Syntax: pico pico is a simple text editor that is fast loading and very easy to use. This is a good choice for quickly editing files, etc... 2. The Internet A. Files archie - search FTP archive for files. Syntax: archie [] Archie searches many ftp sites around the world for a file that matches according the flags it was given. It then displays the result of the search to the screen or to a file. Common Flags: -s : Substring search -e : Exact search (default) -l : Show one find per line -c : Case-sensitive Substring search. -t : sort results by date. -o : output to file ncftp - Enhanced ftp interface. Syntax: ncftp [] [] ncftp is an enhanced version of ftp (see below) that may not be available on all systems. Basic operation is the same as ftp but it shows the path at all times, shows file transfer progress, and has some nice commands like page. Common Flags: -u : ask for user name and password. -a : user name is 'anonymous', password is your email address (default) -r : retry if connection fails. -d : delay between retries -g : give up after tries. ftp - Basic ftp interface. Syntax: ftp [] ftp is the standard way to use ftp. If your system has it ncftp is a far better choice (see above). B. Reaching out gopher - Menu based information retrieval system. Syntax: gopher [] gopher is the standard client for Gopher-Space, a network of 'gopher servers' that works based on menus. This is a simple way to get information, just choose the item you want from the menu. It will either show you another menu, display the file, etc... lynx - World Wide Web hyper-text client. Syntax: lynx lynx is a text based client for the World Wide Web. Basically you see a text file with some words outlined. You can use the tab key to select these words and press returns. This will show you another file . If you have X windows try xmosaic. talk, ytalk - User to user chat. Syntax: talk [@] [] talk will launch a two-window interface that allows real-time chatting between two users. Ytalk allows chatting between multiple users and has some nice options you can access by pressing the escape key. telnet, rlogin - Connect to a remote computer. Syntax: telnet rlogin [-l ] telnet and rlogin both allow you to connect to a remote computer. The major differences are that rlogin does not ask you for a user name and checks a .rhosts file (don't worry about this if you don't understand). And telnet allows you to have some control over your connection by typing control-]. tin, rn, etc... - Usenet news readers. Syntax: varies These are all news readers, there are so many of them and I am not familiar with all of them so I will not put specific information on them in here. Basically they allow you to choose from several thousand subjects and then read and/or post messages that anyone can read. Those famailer with BBSs will recognize this as message boards. finger - Find out information on about a user or a machine. Syntax: finger -l [@] finger @ finger -l will show you information about a user. Last login, shell, etc.. finger @ will show you who is on that host or network. 3. System. A. Getting info on the system. ps - Find out what processes are running on the current machine. Syntax: ps [] ps will show a list of all or some processes running on the machine and some information about them. Default shows your processes. Common flags: -a : show all user (vs. system) processes. -x : show all user and system processes. -u : show which user is running a process and other extra information. w - Show who is on the system and what they are doing. Syntax: w This will show you everyone on the system, what tty they are on, where they logged on from, when they logged on, how long they have been idle, how much CPU they are using total, and how much CPU there foreground process is using (see fg, and bg). who - Show who is on the system Syntax: who This will simply show who is logged on, what tty they are on, when they logged on and where they logged on from. last - Shows a log of connections. Syntax: last [] [] [-] If you specifically a login name then the log will display connections by that user. If you specify a tty then it will show the connections for that tty (the tty is what port the user linked up to). If you specify a - and a number it will only show that many entries of the log. lpq - shows files to be printed. Syntax: lpq lpq will display what files are waiting to be printed and what file is currently being printed. whoami - Shows your login name. Syntax: whoami Simply displays your login name. B. Getting help man - access manual pages. Syntax: man [
] man -k man access a very large online help database and will probably be your main source of reference. The manual pages are divided into several sections (1 user commands,2 system calls, etc..). If you do not signify a section it will search through all sections starting at 1 until it find the command you want. man -k allows you to specify a keyword and it will search for that keyword and display a one line summary on all commands that have to do with that keyword. C. Manipulating the system lock - Locks you terminal Syntax: lock lock prompts you for a password and after verifying it will not allow access to your terminal until the password is typed in. logout - Logs you out of the system. Syntax: logout Logout will log you out of a system. If it does not work try exit instead. exit - exits the shell. Syntax: exit Exit differs from logout in that if you are already logged in (like on a X station) some interfaces will only start a shell (xterm) instead of logging in again. print,lpr - Prints a file. Syntax: print [] Print and lpr both print a file. Both take a variety of flags, etc. The most basic operation is to type print or lpr and the name of a file. Common flags for lpr are: -h : print no header. -P : print to printer . -# : print copies. passwd - Will allow you to change your password. Syntax: passwd passwd simply prompts you for your current password, ask you for a new password, asks you to verify the new password and then changes your password. write - Will display some text on another users screen. Syntax: write [] After typing this command it will no longer show the prompt. Anything you type now not beginning with a ! will be sent to the other person. You can exit this by typing control-d. If you begin a line with a ! then that line is interpreted as a command. - So ends UnixGuide II