Vous êtes sur la page 1sur 37

Computer Facility EMCF Web Design EMCF Helpline Support Computer Lab Schedule Student Computer Requirements Academic

Information Help for Basic UNIX Commands HTML Tutorial Room Combinations Change Your Password Basic Unix Commands More information on almost any of the commands that follow can be found in the on-line manual pages. Type "man command-name" at the command line to look at th e manual page for the command "command-name".

Files -------------------------------------------------------------------------------Display files in a directory :ls Copying files : cp Delete file(s) : rm What kind of file is this ? : file Where is this file ? : find , which, whereis Compile a file : cc, cc++, g++, gcc, CC Debug a program : gdb, dbx, xgdb Whats in this file ? : more, less, cat Whats different with these two files ? diff, cmp View a file in PostScript (.ps file): ghostview Edit a file : emacs, vi, jove Change permission : chmod Finding man page : man -k Moving files : mv Did I spell that right?: spell, ispell Environment -------------------------------------------------------------------------------Keep getting "Can"t open display: :0" :setenv Display current environment variables: env

-------------------------------------------------------------------------------Networking -------------------------------------------------------------------------------Check your mail or mail someone : mail , elm, pine Write message to persons screen: write Graphically display new mail xbiff Information on a person : finger Information on people logged-on rwho Info on Printers : printers Printing a file : lpr Check the print queue : lpq Cancel print jobs :lprm Transfer files over Network : ftp, kermit HOW DO I QUIT !? : logout Information on Servers : rupall Directories -------------------------------------------------------------------------------Where am I now ?? : pwd Moving around : cd , ln Create a directory : mkdir Delete a directory : rmdir Change permissions to a directory : chmod How much disk space do I have left ? quota -v Processes -------------------------------------------------------------------------------What program is running now? jobs, ps -------------------------------------------------------------------------------Passwords -------------------------------------------------------------------------------CHANGE YOUR PASSWORD ! yppasswd

c++ {filename} A compiler for the C++ programming language. Command line parameters are similar to the "cc" compiler"s. A typical invocation might be "c++ -g file.cpp -o execu tablename -llib". -------------------------------------------------------------------------------cat {filename} Prints out ( to the screen ) the contents of the named file. Can also be used to concatenate files. Say you want file1 and file2 to be all together in one file named file3. If file1 is first, then "cat file1 file2 > file3" will produce the correct file3. -------------------------------------------------------------------------------cc A compiler for the "C" programming language. "cc" is ANSI compatible on the SGI, IBM, and newer Sun machines. You might try also try "gcc", GNU CC, which is als o available on the SGI, SUN, and IBM machines. A typical invocation might be "cc -g file.c -o executablename -llib". -------------------------------------------------------------------------------cd {dirname} Change current directory. Without a "dirname", it will return you to your home d irectory. Otherwise, it takes you to the directory named. "cd /" will take you t o the root directory. -------------------------------------------------------------------------------chmod {options} Changes the permission modes of a file. If you type "ls -l" in a directory, you might get something like this: drwx------ 3 ertle 512 Jul 16 13:38 LaTeX/ drwxr-xr-- 2 ertle 512 Jun22 12:26 X/ drwxr-xr-x 3 ertle 512 Jul 13 16:29 Xroff/ -rw-r--r-- 1 ertle 373 Oct 3 1992 o.me -rw-r--r-- 1 ertle 747 Nov 21 1992 profile -rwxr-xr-x 1 ertle 244 Jul 16 23:44 zap* The first part of the line tells you the file"s permissions. For example, the "X " file permissions start with a "d" which tells that it is a directory. The next three characters, "rwx" show that the owner has read, write, and execute permis sions on this file. The next three characters, "r-x" shows that people in the sa me group have read and execute permission on the file. Finally, the last three c haracters "r-" show that everyone else only has read permission on that file ( T o be able to enter a directory, you need read AND execute permission ). Users ca n use "chmod" to change these permissions. If the user didn"t want anybody else to be able to enter the "X" directory, they would change the permissions to look like those of the LaTeX directory, like this : "chmod og-rx X" - this means rem ove the read ("r" ) and execute ("x") permissions from the group ("g") and other s ("o"). -------------------------------------------------------------------------------cmp {file1} {file2} Compares the contents of two files from eachother. Reports the first different c haracter found, and the line nummber. -------------------------------------------------------------------------------cp {filename(s)}{path} Copies files from one directory/filename to another. "cp f1 f2" makes a file "f2

" identical to "f1". "cp *.c src/" copies all files that end in ".c" into the "s rc" subdirectory. -------------------------------------------------------------------------------ctags Creates a tags file for use with ex and vi. A tags file gives the location of fu nctions and type definitions in a group of files. ex and vi use entries in the t ags file to locate and display a definition. -------------------------------------------------------------------------------date Shows current date and time. -------------------------------------------------------------------------------dbx {executable} Source level debugger. In order to use this, you must use the "-g" option when c ompiling your source code. Allows you to set break-points, single step through t he program, etc. -------------------------------------------------------------------------------diff {file1} {file2} Displays all the differences between two files or directories to the screen. -------------------------------------------------------------------------------elm {login-name} Runs a screen oriented mail reader. With a "login-name", starts elm to send mail to "login-name". Otherwise, it starts elm for an interactive session. -------------------------------------------------------------------------------emacs {filename} Runs the most recent version of the text editor named EMACS ( produced by the GN U project ). If filename is present, it will start editing that file. Type "<CTR L>-x <CTRL>-h t" to start a tutorial. "<CTRL>-x <CTRL>-c" will exit from emacs. -------------------------------------------------------------------------------env Prints out the values for all the current environment variables. Some typical en vironment variables are "DISPLAY", "EDITOR", and "PRINTER". -------------------------------------------------------------------------------xemacs {filename} An X version of emacs. -------------------------------------------------------------------------------file filename(s) Looks at "filename(s)" and tells what type of files they are. This is useful in checking a file to be sure that it is text before you "cat" it out ( using "cat" on binary files can be a bummer ). Example: ertle@newton (55)> file * useful.dvi: data useful.hlp: English text useful.tex: ascii text xwin.dvi: data xwin.tex: English text ertle@newton (56)> -------------------------------------------------------------------------------find

Searches the named directory and it"s sub-directories for files. Most frequently called like this: find ./ -name "t*" -print Which searches the current directory ( and all of its sub-directories ) for any files that begin with the letter "t" and then prints them out. If you are lookin g for a specific filename, then replace "t*" with "filename", and "find" will pr int out all incidences of this file. -------------------------------------------------------------------------------finger {login-name} Without a "login-name", finger shows who is currently logged on the system, with limited information about them. With a "login-name" you get more detailed info, along with anything that is in that person"s ".plan" file. -------------------------------------------------------------------------------ftp {address} File Transfer Program. "ftp" transfers files to and from a remote network site. There are many ftp-sites that will let you log in as "anonymous" and get softwar e/data/documents from them for free. After connecting, "ls" will print out the f iles in the current directory, and "get filename" will transfer the named file i nto your local directory. Be sure to type "binary" before transferring non-ascii ( executable, compressed, archived, etc ) files. To exit "ftp" type "bye". See also "xarchie". -------------------------------------------------------------------------------g++ GNU project"s compiler for the C++ language. Parameters are similar to those of "cc". A typical invocation might be "g++ -g filename.cpp -o executablename -llib ". More information available under "libg++" in the emacs information browser ( M-x info while in emacs ). -------------------------------------------------------------------------------gcc GNU project"s compiler for the C language. Command line parameters are mostly si milar to those of "cc". More information available under "gcc" in the emacs info rmation browser ( M-x info while in emacs ). -------------------------------------------------------------------------------gdb GNU project"s source level debugger. Must use the "-g" command line option when compiling to use this debugger. This debugger is superior to dbx when called fro m inside emacs ( M-x gdb ) because it gives you a full-screen look at the source code instead of line by line, and allows you to move around and make break-poin ts in the source file. More information available under "gdb" in the emacs infor mation browser ( M-x info while in emacs ). -------------------------------------------------------------------------------ghostview {filename.ps} X PostScript previewer. PostScript is a text processing and graphics language, a nd ghostview is handy for looking at the resulting page or picture before you se nd it to the printer. -------------------------------------------------------------------------------gossip Anonymous local message center. --------------------------------------------------------------------------------

ispell filename Interactively checks the spelling of the named file, giving logical alternatives to the misspelled words. Type "?" to get help. "ispell" can be accessed from th e command line, and also through emacs with M-x ispell-buffer. -------------------------------------------------------------------------------jobs Shows backgrounded (<CTRL>-z"ed) processes with pid #"s. If you use "jobs" to fi nd the processes that you have suspended or are running in the background, what you get back might look like the following: [1] 21998 Suspended emacs useful.tex [2] - 22804 Suspended (signal) elm [3] + 22808 Suspended badb -------------------------------------------------------------------------------jove {filename} Johnathan"s Own Version of Emacs. Another emacs editor. Jove doesn"t have as man y features as GNU"s emacs, but some people prefer it. <CTRL>-x <CTRL>-c to exit. -------------------------------------------------------------------------------less filename Displays file with minimal space. kermit File transfer program. Allows you to transfer files between computers - your PC at home to/from the computers at school, for instance. For more information, loo k in the online manual pages. -------------------------------------------------------------------------------ln -s {source} {dest} Creates a symbolic link from {source} to {dest}. {Source} can be a directory or a file. Allows you to move around with ease instead of using long and complicated path n ames. -------------------------------------------------------------------------------logout Exits and disconnects your network connection. -------------------------------------------------------------------------------lpq {-Pprintername} Reports all print jobs in the queue for the named printer. If no printer is name d with -Pprintername, but the "PRINTER" environment variable is set to a printer name, "lpq" will report on that printer. -------------------------------------------------------------------------------lpr {-Pprintername}filename Queues file "filename" to be printed on "printer". If no printer is specified wi th -Pprintername, but the "PRINTER" environment variable is set, then the job wi ll be queued on that printer. -------------------------------------------------------------------------------lprm {-Pprinter}{job-number} Lprm removes a job or jobs from a printer"s spooling queue ( i.e. it stops it fr om being printed or printing out the rest of the way ). Typically, you"d get the job number from the "lpq" command, and then use lprm to stop that job. --------------------------------------------------------------------------------

ls {directory} Shows directory listing. If no "directory" is specified, "ls" prints the names o f the files in the current directory. ls -l {directory} Shows long directory listing. If you type "ls -l" in a directory, you might get something like this: drwx------ 3 ertle 512 Jul 16 13:38 LaTeX/ drwxr-xr-- 2 ertle 512 Jun 22 12:26 X/ drwxr-xr-x 3 ertle 512 Jul 13 16:29 Xroff/ -rw-r--r-- 1 ertle 373 Oct 3 1992 o.me -rw-r--r-- 1 ertle 747 Nov 21 1992 profile -rwxr-xr-x 1 ertle 244 Jul 16 23:44 zap* The first part of the line tells you the file"s permissions. For example, the "X " file permissions start with a "d" which tells that it is a directory. The next three characters, "rwx" show that the owner has read, write, and execute permis sions on this file. The next three characters, "r-x" shows that people in the sa me group have read and execute permission on the file. Finally, the last three c haracters "r-" show that everyone else only has read permission on that file ( T o be able to enter a directory, you need read AND execute permission ) -------------------------------------------------------------------------------mail {login-name} Read or send mail messages. If no "login-name" is specified, "mail" checks to se e if you have any mail in your mail box. With a "login-name", "mail" will let yo u type in a message to send to that person. For more advanced mail processing, y ou might try "elm" or "pine" at the command line, or "M-x mail" in emacs. -------------------------------------------------------------------------------mkdir dirname Makes a sub-directory named "dirname" in the current directory. -------------------------------------------------------------------------------man -k pattern Shows all manual entries which have "pattern" in their description. -------------------------------------------------------------------------------man {section}name Shows the full manual page entry for "name". Without a section number, "man" may give you any or all man pages for that "name". For example, "man write" will gi ve you the manual pages for the write command, and "man 2 write" will give you t he system call for "write" ( usually from the C or Pascal programming language ) . -------------------------------------------------------------------------------more filename Displays the contents of a file with pagebreaks. Usefull to use "file" first so you don"t display garbage. mv filename path Moves "filename" to "path". This might consist of a simple renaming of the file, "mv file1 file2", moving the file to a new directory, "mv file1 /tmp/", or both "mv file1 /tmp/file2". -------------------------------------------------------------------------------pine Full featured graphical mail reader/sender. "pine" will read your mail, "pine us ername" will prepare a message to "username". --------------------------------------------------------------------------------

printers Shows available printers and current status. -------------------------------------------------------------------------------ps {options} "ps" reports that status of some or all of the processes currently running on th e system. With no command line parameters, "ps" only shows processes that belong to you and that are attached to a controlling terminal. -------------------------------------------------------------------------------pwd Shows current working directory path. -------------------------------------------------------------------------------quota -v Shows current disk usage and limits. -------------------------------------------------------------------------------rm filename(s) Removes files. Careful with this one - it is irreversible. It is usually aliased ( in a user"s .cshrc file ) to "rm -i" which insures that "rm" asks you if you are sure that you want to remove the named file. -------------------------------------------------------------------------------rmdir dirname Removes the directory "dirname". -------------------------------------------------------------------------------rupall Reports that status of local compute servers. -------------------------------------------------------------------------------rwho Similar to "who", but shows who is logged onto all emba machines as well as the local machine. Without "-a", rwho shows all the people with under one hour idle time. With the "-a", rwho shows everybody that is logged on. --------------------------------------------------------------------------------

-------------------------------------------------------------------------------setenv Sets environment variables. Most frequently used to tell X which display you are on with "setenv DISPLAY displayname:0". Also used in .cshrc file to set "EDITOR " and "PRINTER" environment variables. This tells programs which editor you pref er, and which printer you want your output to be printed on. -------------------------------------------------------------------------------spell {filename} Checks the spelling of the words in the standard input by default, checks words in "filename" if a name is supplied on the command line. If a word is misspelled it is printed to stdout ( usually the screen ). -------------------------------------------------------------------------------trn Threaded, full page network news reader. Quicker than vn. --------------------------------------------------------------------------------

tin Threaded, full page network news reader. Easier to use than trn. -------------------------------------------------------------------------------vi {filename} Runs the screen oriented text editor named "vi". If a filename is specified, you will be editing that file. Type "[ESC]:q!" to exit without making any changes. -------------------------------------------------------------------------------vn Runs the screen oriented network news program. Old and slow - maybe try "trn" or "tin". --------------------------------------------------------------------------------------------------------------------------------------------------------------whereis {command} Reports the directory in which the {command} binary redides. -------------------------------------------------------------------------------which {command} Reports the directory from which the {command} would be run if it was given as a command line argument. -------------------------------------------------------------------------------who Shows who is currently logged on the system. The "w" command does the same thing , but gives slightly different info. -------------------------------------------------------------------------------write loginname Send a message to another user. Each line will be sent to the other person as yo u hit the carriage-return. Press <CTRL>-D to end the message. Write won"t work i f the other user has typed "mesg n". -------------------------------------------------------------------------------xbiff X mailbox flag. The xbiff program displays a little image of a mailbox. When the re is no mail, the flag on the mailbox is down. When mail arrives, the flag goes up and the mailbox beeps. This program must be started on one of the machines t hat you receive mail on. This will be one of the Suns ( griffin, sadye, newton, etc ) for most people. -------------------------------------------------------------------------------xcalc X scientific calculator. -------------------------------------------------------------------------------xcalendar X calendar. Interactive calendar program with a notebook capability. -------------------------------------------------------------------------------xclock X clock. -------------------------------------------------------------------------------xforecast X interface to national weather forecast. --------------------------------------------------------------------------------

xgdb X interface to the gdb debugger. -------------------------------------------------------------------------------xman X interface to the online manual pages. -------------------------------------------------------------------------------yppasswd Interactively changes your password. --------------------------------------------------------------------------------------------------------------------------------------------------------------Click Here for more advanced UNIX commands. If you have any questions or concerns about these pages, please contact Webmaste r Contact Info: Call 1-800-ENG-MATH OR E-Mail Student Services OR Fill out a Reque st Form copyright 2000. All rights reserved. University of Vermont

Next / Previous / Index / TCC Help System / Publications / Site map / NM Tech ho mepage Finding out what files you have Once you log in to your account, you can see what files you have by using the ls command: % lsThis command will give you a list of all the names of your files. If y ou just got your account, you won't see any names until you actually create some files. Here's an example. Suppose you type an ls command and it produces this output: % ls groceries schedule todoThis is telling you that you have three files. In alph abetical order, their names are groceries, schedule, and todo. -------------------------------------------------------------------------------Next: Using ls command options See also: Organizing your files; Making a copy of a file Site map Index: Keyword index to help pages Help: New Mexico Tech Computer Center: Help System TCC Publications Home: About New Mexico Tech

-------------------------------------------------------------------------------John Shipman, john@nmt.edu Last updated: 1995/12/04 19:39:34 UT URL: http://www.nmt.edu/tcc/help/unix/ls.html

basic unix commands

Basic UNIX commands Note: not all of these are actually part of UNIX itself, and you may not find th em on all UNIX machines. But they can all be used on turing in essentially the s ame way, by typing the command and hitting return. Note that some of these comma nds are different on non-Solaris machines - see SunOS differences. If you've made a typo, the easiest thing to do is hit CTRL-u to cancel the whole line. But you can also edit the command line (see the guide to More UNIX). UNIX is case-sensitive. Files ls --- lists your files ls -l --- lists your files in 'long format', which contains lots of useful infor mation, e.g. the exact size of the file, who owns the file and who has the right to look at it, and when it was last modified. ls -a --- lists all files, including the ones whose filenames begin in a dot, wh ich you do not always want to see. There are many more options, for example to list files by size, by date, recursi vely etc. more filename --- shows the first part of a file, just as much as will fit on on e screen. Just hit the space bar to see more or q to quit. You can use /pattern to search for a pattern. emacs filename --- is an editor that lets you create and edit a file. See the em acs page. mv filename1 filename2 --- moves a file (i.e. gives it a different name, or move s it into a different directory (see below) cp filename1 filename2 --- copies a file rm filename --- removes a file. It is wise to use the option rm -i, which will a sk you for confirmation before actually deleting anything. You can make this you r default by making an alias in your .cshrc file. diff filename1 filename2 --- compares files, and shows where they differ wc filename --- tells you how many lines, words, and characters there are in a f ile chmod options filename --- lets you change the read, write, and execute permissi ons on your files. The default is that only you can look at them and change them , but you may sometimes want to change these permissions. For example, chmod o+r filename will make the file readable for everyone, and chmod o-r filename will make it unreadable for others again. Note that for someone to be able to actuall y look at the file the directories it is in need to be at least executable. See help protection for more details.

File Compression gzip filename --- compresses files, so that they take up much less space. Usuall y text files compress to about half their original size, but it depends very muc h on the size of the file and the nature of the contents. There are other tools for this purpose, too (e.g. compress), but gzip usually gives the highest compre ssion rate. Gzip produces files with the ending '.gz' appended to the original f ilename. gunzip filename --- uncompresses files compressed by gzip. gzcat filename --- lets you look at a gzipped file without actually having to gu nzip it (same as gunzip -c). You can even print it directly, using gzcat filenam e lpr printing lpr filename --- print. Use the -P option to specify the printer name if you wan t to use a printer other than your default printer. For example, if you want to print double-sided, use 'lpr -Pvalkyr-d', or if you're at CSLI, you may want to use 'lpr -Pcord115-d'. See 'help printers' for more information about printers a nd their locations. lpq --- check out the printer queue, e.g. to get the number needed for removal, or to see how many other files will be printed before yours will come out lprm jobnumber --- remove something from the printer queue. You can find the job number by using lpq. Theoretically you also have to specify a printer name, but this isn't necessary as long as you use your default printer in the department. genscript --- converts plain text files into postscript for printing, and gives you some options for formatting. Consider making an alias like alias ecop 'gensc ript -2 -r \!* lpr -h -Pvalkyr' to print two pages on one piece of paper. dvips filename --- print .dvi files (i.e. files produced by LaTeX). You can use dviselect to print only selected pages. See the LaTeX page for more information about how to save paper when printing drafts. Directories Directories, like folders on a Macintosh, are used to group files together in a hierarchical structure. mkdir dirname --- make a new directory cd dirname --- change directory. You basically 'go' to another directory, and yo u will see the files in that directory when you do 'ls'. You always start out in your 'home directory', and you can get back there by typing 'cd' without argume nts. 'cd ..' will get you one level up from your current position. You don't hav e to walk along step by step - you can make big leaps or avoid walking around by specifying pathnames. pwd --- tells you where you currently are. Finding things ff --- find files anywhere on the system. This can be extremely useful if you've forgotten in which directory you put a file, but do remember the name. In fact, if you use ff -p you don't even need the full name, just the beginning. This ca n also be useful for finding other things on the system, e.g. documentation. grep string filename(s) --- looks for the string in the files. This can be usefu l a lot of purposes, e.g. finding the right file among many, figuring out which is the right version of something, and even doing serious corpus work. grep come s in several varieties (grep, egrep, and fgrep) and has a lot of very flexible o ptions. Check out the man pages if this sounds good to you. About other people w --- tells you who's logged in, and what they're doing. Especially useful: the 'idle' part. This allows you to see whether they're actually sitting there typin g away at their keyboards right at the moment. who --- tells you who's logged on, and where they're coming from. Useful if you' re looking for someone who's actually physically in the same building as you, or in some other particular location. finger username --- gives you lots of information about that user, e.g. when the y last read their mail and whether they're logged in. Often people put other pra ctical information, such as phone numbers and addresses, in a file called .plan.

This information is also displayed by 'finger'. last -1 username --- tells you when the user last logged on and off and from whe re. Without any options, last will give you a list of everyone's logins. talk username --- lets you have a (typed) conversation with another user write username --- lets you exchange one-line messages with another user elm --- lets you send e-mail messages to people around the world (and, of course , read them). It's not the only mailer you can use, but the one we recommend. Se e the elm page, and find out about the departmental mailing lists (which you can also find in /user/linguistics/helpfile). About your (electronic) self whoami --- returns your username. Sounds useless, but isn't. You may need to fin d out who it is who forgot to log out somewhere, and make sure *you* have logged out. finger & .plan files of course you can finger yourself, too. That can be useful e.g. as a quick check whether you got new mail. Try to create a useful .plan file soon. Look at other people's .plan files for ideas. The file needs to be readable for everyone in o rder to be visible through 'finger'. Do 'chmod a+r .plan' if necessary. You shou ld realize that this information is accessible from anywhere in the world, not j ust to other people on turing. passwd --- lets you change your password, which you should do regularly (at leas t once a year). See the LRB guide and/or look at help password. ps -u yourusername --- lists your processes. Contains lots of information about them, including the process ID, which you need if you have to kill a process. No rmally, when you have been kicked out of a dialin session or have otherwise mana ged to get yourself disconnected abruptly, this list will contain the processes you need to kill. Those may include the shell (tcsh or whatever you're using), a nd anything you were running, for example emacs or elm. Be careful not to kill y our current shell - the one with the number closer to the one of the ps command you're currently running. But if it happens, don't panic. Just try again :) If y ou're using an X-display you may have to kill some X processes before you can st art them again. These will show only when you use ps -efl, because they're root processes. kill PID --- kills (ends) the processes with the ID you gave. This works only fo r your own processes, of course. Get the ID by using ps. If the process doesn't 'die' properly, use the option -9. But attempt without that option first, becaus e it doesn't give the process a chance to finish possibly important business bef ore dying. You may need to kill processes for example if your modem connection w as interrupted and you didn't get logged out properly, which sometimes happens. quota -v --- show what your disk quota is (i.e. how much space you have to store files), how much you're actually using, and in case you've exceeded your quota (which you'll be given an automatic warning about by the system) how much time y ou have left to sort them out (by deleting or gzipping some, or moving them to y our own computer). du filename --- shows the disk usage of the files and directories in filename (w ithout argument the current directory is used). du -s gives only a total. last yourusername --- lists your last logins. Can be a useful memory aid for whe n you were where, how long you've been working for, and keeping track of your ph onebill if you're making a non-local phonecall for dialling in. Connecting to the outside world nn --- allows you to read news. It will first let you read the news local to tur ing, and then the remote news. If you want to read only the local or remote news , you can use nnl or nnr, respectively. To learn more about nn type nn, then \tt y{:man}, then \tty{=.*}, then \tty{Z}, then hit the space bar to step through th e manual. Or look at the man page. Or check out the hypertext nn FAQ - probably the easiest and most fun way to go. rlogin hostname --- lets you connect to a remote host telnet hostname --- also lets you connect to a remote host. Use rlogin whenever possible. ftp hostname --- lets you download files from a remote host which is set up as a

n ftp-server. This is a common method for exchanging academic papers and drafts. If you need to make a paper of yours available in this way, you can (temporaril y) put a copy in /user/ftp/pub/TMP. For more permanent solutions, ask Emma. The most important commands within ftp are get for getting files from the remote mac hine, and put for putting them there (mget and mput let you specify more than on e file at once). Sounds straightforward, but be sure not to confuse the two, esp ecially when your physical location doesn't correspond to the direction of the f tp connection you're making. ftp just overwrites files with the same filename. I f you're transferring anything other than ASCII text, use binary mode. lynx --- lets you browse the web from an ordinary terminal. Of course you can se e only the text, not the pictures. You can type any URL as an argument to the G command. When you're doing this from any Stanford host you can leave out the .st anford.edu part of the URL when connecting to Stanford URLs. Type H at any time to learn more about lynx, and Q to exit. Miscellaneous tools webster word --- looks up the word in an electronic version of Webster's diction ary and returns the definition(s) date --- shows the current date and time. cal --- shows a calendar of the current month. Use e.g., 'cal 10 1995' to get th at for October 95, or 'cal 1995' to get the whole year. You can find out more about these commands by looking up their manpages: man commandname --- shows you the manual page for the command For further ways of obtaining help, look at the pages with electronic sources of information and non-electronic sources. More UNIX commands -------------------------------------------------------------------------------Back up to the Main Computing Page --------------------------------------------------------------------------------

Unix commands reference card -------------------------------------------------------------------------------Environment Control Command cd d mkdir d Description Change to directory d Create new directory d

rmdir d mv f1 [f2...] d mv d1 d2 passwd alias name1 name2 alias name1="name2" unalias name1[na2...] ssh nd exit sentenv name v export name="v"

Remove directory d Move file f to directory d Rename directory d1 as d2 Change password Create command alias (csh/tcsh) Create command alias (ksh/bash) Remove command alias na Login securely to remote node End terminal session Set env var to value v (csh/tcsh) set environment variable to value v (ksh/bash)

-------------------------------------------------------------------------------Output, Communication, & Help Command Description lpr -P printer f or lp -d printer f script [f] exit mailx username man name

Output file f to line printer Save terminal session to f Stop saving terminal session Send mail to user Unix manual entry for name

-------------------------------------------------------------------------------Process Control Command CTRL/c * CTRL/s * CTRL/q * sleep n Description Interrupt processes Stop screen scrolling Resume screen output Sleep for n seconds

jobs kill % ps kill -9 n CTRL/z * stop %n cmmd& bg [%n] fg [%n] exit

Print list of jobs Kill job n Print process status stats Remove process n Suspend current process Suspend background job n Run cmmd in background Resume background job n Resume foreground job n Exit from shell

-------------------------------------------------------------------------------Environment Status Command ls [d] [f...] ls -1 [f...] alias [name] printenv [name] quota date who whoami finger [username] chfn pwd history ! n Description List files in directory List files in detail Display command aliases Print environment values Display disk quota Print date & time List logged in users Display current user Output user information Change finger information Print working directory Display recent commands Submit recent command n

-------------------------------------------------------------------------------File Manipulation Command Description

vi [f] emacs [f] ed [f] wc f cat f more f cat f1 f2 >f3 chmod mode f cmp f1 f2 cp f1 f2 sort f split [-n] f mv f1 f2 rm f grep 'ptn' f diff f1 f2 head f tail f

Vi fullscreen editor Emacs fullscreen editor Text editor Line, word, & char count List contents of file List file contents by screen Concatenates f1 & f2 into f3 Change protection mode of f Compare two files Copy file f1 into f2 Alphabetically sort f Split f into n-line pieces Rename file f1 as f2 Delete (remove) file f Outputs lines that match ptn Lists file differences Output beginning of f Output end of f

-------------------------------------------------------------------------------Compiler Command cc [-o f1] f2 lint f f77 [-o f1] f2 pc [-o f1] f2 Description C compiler Check C code for errors Fortran77 compiler Pascal compiler

-------------------------------------------------------------------------------Working with NFS files Files saved on the UITS central Unix computers Steel, the Parallel PC cluster, S olar/Lunar, and the Research SP are stored on the Network File Server (NFS). Tha t means that your files are really on one disk, in directories named for the cen tral Unix hosts on which you have accounts.

No matter which of these computers you are logged into, you can get to your file s on any of the others. Here are the commands to use to get to any system direct ory from any other system: cd /N/u/username/PPPC/ cd /N/u/username/Cobalt/ cd /N/u/username/Solar/ cd /N/u/username/Steel/ cd /n/u/username/SP/ Be sure you use the capitalization just as you see above, and substitute your ow n username for "username". For example, if Jessica Rabbit is logged into her account on Steel, and wants to get a file on her SP account, she would enter: cd /N/u/jrabbit/SP/ Now when she lists her files, she'll see her SP files, even though she's actuall y logged into Steel. You can use the ordinary Unix commands to move files, copy files, or make symbol ic links between files. For example, if Jessica Rabbit wanted to move "file1" fr om her Steel directory to her SP directory, she would enter: mv -i /N/u/jrabbit/Steel/file1 /N/u/jrabbit/SP/ This shared file system means that you can access, for example, your SP files ev en when you are logged into Steel, and vice versa. However, if you are logged in to the SP, you can only use the software installed on SP -- only users' director ies are linked together, not system directories.

-------------------------------------------------------------------------------Abbreviations used in this document CTRL/x d env f n nd prtr ptn var [y/n] [] ... hold down control key and press x directory environment filename number computer node printer pattern variable yes or no optional arg list

-------------------------------------------------------------------------------Printing this how-to guide A printable version of this guide is available in Adobe Acrobat's Portable Docum ent Format (PDF). To print the PDF file, you need special software, such as the Acrobat Reader or the Acrobat Netscape plug-in. Everything you need for this is in the UITS Student Technology Centers. If you have trouble accessing a PDF file , notify the lab consultant. If you're at a personal computer and don't have the necessary software, you can download and install the Acrobat reader on your system. You'll need to do this s tep only once. To print this guide: Download Unix commands: A quick guide (Acrobat/pdf format). Use Acrobat to print the document. If you wish to print this guide from your browser, please consult the browser's printing instructions.

-------------------------------------------------------------------------------Last updated: August 2000 http://www.indiana.edu/~uitspubs/b017/ Comments: ithelp@indiana.edu Copyright 1995-2000, The Trustees of Indiana University

Top Ten Unix Commands Last update: Wednesday, 05-Oct-2005 16:29:14 CDT

Contents: man ls cd, mkdir rm, rmdir cp

mv lynx, netscape pine, pico finger host dig Additional Information -------------------------------------------------------------------------------Please note: Text that appears in a typewriter style is used to show commands that you can ty pe. Text that is in square brackets, [ ], indicates a set of options that can be use d with a command. The commands referred to here will work on Unix systems operated by Academic Com puting and Networking at the University of Manitoba. Some of these commands may work differently or may not be available on other Unix systems at the University or at other locations. -------------------------------------------------------------------------------Display Manual Pages: "man" The man command will display the manual pages for most UNIX commands. For more i nformation on any of the Unix commands below, use this to see if there is an onl ine manual page available. For example, if you require help on the move (mv) com mand, you would type: man mv The command syntax for man is: man commandname By default, the man command uses another command called more to display the manu al page one screenfull at a time. To display the next screen, press the space ba r. To end the display before the end of the file, press the "q" key. The Unix man pages are also available on-line from the Suns Document Pages. List the contents of a directory: "ls" Use this command to list the contents of the current directory. This will displa y all files and directories within the current directory in a columnar format. You may change the format in which ls displays your directory listing by adding options to the ls command. To add an option to the command, follow the ls comman d with a minus sign '-' and the option(s) you wish to add. For example, ls -l wi ll list the current directory in long format, showing size, date, and permission s. ll is a common alias or shortcut for the list long command (ls -l). In Unix, there are files which are normally hidden called "dotfiles". These dotf iles are files that start with a dot (i.e. a period - ".") and are used by progr ams and shells to retain control information such as preference settings and boo kmarks. To see hidden files, use ls -a to list all files, including those files whose names begin with a period. Be careful not to remove dotfiles if you're not sure of their purpose.

The command syntax for ls is : ls [ -aAcCdfFgilLqrstux ] filename If you use the ls command on a directory with many files, the display will proba bly scroll off the screen. To avoid this, you can "pipe" the display through the more command, just as with man pages. The Unix "pipe" symbol is a vertical bar (often a broken vertical bar on your keyboard). It means "take the command on th e left, and use it as input to the command on the right". For example: ls -la more

Which lists the content of the current directory, in long format (-l) and includ es all files (-a), and sends the listing to the more command which displays the listing one screen at a time. For more complete information on the ls command, try man ls. Change Directory: "cd" and Make Directory: "mkdir" The "change directory" command is used to switch from one directory to another. The purpose of having multiple directories is to enable you to easily organize y our files. Your directory structure should resemble a filing cabinet, with folde rs (directories) for each set of files. Using cd without a directory name following it will always return you to your ho me directory, no matter where you are in the Unix directories. To change to a su bdirectory, for example one called "skiing", you would type: cd skiing To "back up" a level in the directory structure from a subdirectory to its paren t directory, you can use: cd .. .. is a special directory which always links a directory backwards to its parent directory, you can see this directory with the ls -a command. There is a second special directory called . which always refers to the current directory. The command syntax for cd is : cd [directoryname] For more complete information on the cd command, try man cd. The "make directory" command is used to create a new directory. As noted above, a directory serves to organize files in a manner to similar to a filing cabinet. However, unlike most filing cabinets, a single directory may contain several su bdirectories. For example, to create a directory called "Banff": mkdir Banff The command syntax for mkdir is: mkdir directoryname For more complete information on the mkdir command, try man mkdir. Remove files: "rm" and Remove directories: "rmdir" The "remove" command is used to permanently delete your files from your director

ies. To remove a file named "whistler.ps" from the current directory: rm whistler.ps To remove multiple files, use the remove command followed by the names of the fi les, separated by spaces. For example: rm file1 file2 file3 The command syntax for rm is: rm [-fir] filename The "remove directory" command is used to delete your directories. The directory you wish to remove must be empty before using the rmdir command. To remove a di rectory called "bigsky", you would type: rmdir bigsky The command syntax for rmdir is: rmdir directoryname To remove a directory that is not empty (and all of its contents) you can use th e rm command with the -r (recursive) option. This will recursively remove all fi les from a directory (or subdirectories) and then remove the directory itself. R epeating the previous example: rm -r bigsky For more complete information on the rm and rmdir commands, try man rm, man rmdir. Copy files: "cp" The "copy" command is used to make a copy of a file in the same or a different d irectory. If copying to the same directory the filename of the copy must be diff erent. This is useful for making backups or working copies of files while leavin g the originals alone. To copy the file tahoe.txt to a backup file tahoe.txt.bak in the same directory: cp tahoe.txt tahoe.txt.bak To copy the file named "tahoe.txt" from your home directory to a directory named "goodskiing" (without changing the name): cp tahoe.txt goodskiing If you wished to rename the copied file: cp tahoe.txt goodskiing/newname.txt The command syntax for cp is: cp [ -ip ] filename1 filename2 For more complete information on the cp command, try man cp. Move or Rename Files: "mv" The "move" command is used to move or rename files.

For example, to move a file named "panorama.ps" from your home directory to a di rectory named "goodskiing", you would type: mv panorama.ps goodskiing The "move" command can also be used to rename files or directories. If you wante d to rename a file called "mammoth.ps" to "BIG.ps" (remember that UNIX is case s ensitive!), you would type: mv mammoth.ps BIG.ps Finally you can move and rename at the same time by specifying a new file name a long with the directory to move to: mv mammoth.ps goodskiing/BIG.ps The command syntax for mv is: mv [ -fi ] filename1 filename2 For more complete information on the mv command, try man mv. Browse Information on the World-wide Web: "netscape", "lynx" Netscape and Lynx are two web browsers available on the Unix system. Netscape of fers a graphical interface most familiar to browsers on other systems, while Lyn x offers a text only browser interface. Lynx can be useful if you want quick acc ess to information, or are using a text based terminal. To start Netscape you must be logged into the CDE. Then type netscape at any Uni x prompt, or click on its icon in the workspace menu. To start Lynx type lynx in any Unix session. By default Lynx will startup displa ying the U of M's home page. If you wish to have lynx browse a certain page once it starts, you can type: lynx URL For specific information on running lynx try How to View the Web in Text Only wi th Lynx. pine and pico Typing pine at the UNIX prompt will start up a simple but effective text base ma il program. Pine allows you to receive, compose, send and organize e-mail messag es, corresponding with anyone around the world who is connected to the Internet. Messages composed in Pine are editted using a file editor program called "pico" (for PIne COmposer). The command pico can also be used from the UNIX prompt to c reate and edit other files. By default, pico will break up long lines between wo rds, which gives a better appearance in most mail-reading programs. To create a file called "filename" with pico type: pico -w filename Pine and Pico both have help features. For a more extensive introduction to thes e programs, see: How to Use Pine for Email, or for additional topics the Pine In dex. Get Information About Someone On Unix: finger

Finger is used to display information about users on UNIX systems. Finger displa ys a user's full name, last login, and when the user last read their mail. If yo u wished to find out information about a user on campus, you would type finger u ser_name. If you wished to finger a user on the Internet, you would type finger username@host. You can also enhance the operation of finger by appending options to the finger command. For instance, if you know the person's full userid, you would then type finger -m username, which is much quicker than the normal finger command. The command syntax for finger is: finger [-mlsqibfwhp] [username] For more complete information on the finger command, try man finger. Get Information About a Host Machine: host Although old, the host command lets learn about a machines 'host' information. Get Information About a Host Machine: dig Although old, the dig command lets learn about a machines 'host' information. Additional Information... If you do not know the name of a file, but part of the name, you can use the * t o signify the unknown part of the name. For example, to remove every file that e nds in .ps, you would type rm *.ps UNIX is case sensitive! Academic Computing and Networking sometimes offers introductory courses on UNIX. For information see: http://www.umanitoba.ca/campus/ist/training The Campus Bookstore has Dr. Salomon's Unix Cookbook, a great quick reference av ailable for purchase. Send comments to Support Desk Supervisor: support@cc.umanitoba.ca http://www.umanitoba.ca/acn/support/top10unx.html Search the Support Desk FAQ pages: Match: AllAnyBoolean Format: LongShort Sort by: ScoreTimeTitleReverse ScoreRe verse TimeReverse Title Search:

Skip to content Home Menus Glossary Help Text size: Enter search terms: Include archived documents 10 15 20 50 100 200 300 Search results per page Introduction to Unix commands This is a very brief introduction to some useful Unix commands, including exampl es of how to use each command. For more extensive information about any of these commands, use the man command as described below. At the end of this document y ou will find sources for more information. Commands cal cat cd chmod cp date df du find jobs kill less and more lpr and lp ls man mkdir

mv ps pwd rm rmdir set vi w and who cal This command will print a calendar for a specified month and/or year. To show this month's calendar, enter: cal To show a twelve-month calendar for 2004, enter: cal 2004 To show a calendar for just the month of June, 1970, enter: cal 6 1970 For more detailed information, see the Knowledge Base document In Unix, how can I display a calendar? cat This command outputs the contents of a text file. You can use it to read brief f iles or to concatenate files together. To append file1 onto the end of file2, enter: cat file1 >> file2 To view the contents of a file named myfile, enter: cat myfile Because cat displays text without pausing, its output may quickly scroll off you r screen. Use the less command (described below) or an editor for reading longer text files. For more detailed information, see the Knowledge Base document In Unix, how do I combine several files into a single file? cd This command changes your current directory location. By default, your Unix logi n session begins in your home directory. To switch to a subdirectory (of the current directory) named myfiles, enter: cd myfiles To switch to a directory named /home/dvader/empire_docs, enter: cd /home/dvader/empire_docs To move to the parent directory of the current dir ectory, enter: cd .. To move to the root directory, enter: cd / To return to your home directory, enter: cd chmod This command changes the permission information associated with a file. Every fi le (including directories, which Unix treats as files) on a Unix system is store d with records indicating who has permission to read, write, or execute the file , abbreviated as r, w, and x. These permissions are broken down for three catego ries of user: first, the owner of the file; second, a group with which both the user and the file may be associated; and third, all other users. These categorie s are abbreviated as u for owner (or user), g for group, and o for other.

To allow yourself to execute a file that you own named myfile, enter: chmod u+x myfile To allow anyone who has access to the directory in which myfi le is stored to read or execute myfile, enter: chmod o+rx myfile You can view the permission settings of a file using the ls command, described below. Note: Be careful with the chmod command. If you tamper with the directory permis sions of your home directory, for example, you could lock yourself out or allow others unrestricted access to your account and its contents. For more detailed information, see the Knowledge Base document In Unix, how do I change the permissions for a file? cp This command copies a file, preserving the original and creating an identical co py. If you already have a file with the new name, cp will overwrite and destroy the duplicate. For this reason, it's safest to always add -i after the cp comm and, to force the system to ask for your approval before it destroys any files. The general syntax for cp is: cp -i oldfile newfile To copy a file named meeting1 in the directory /home/dva der/notes to your current directory, enter: cp -i /home/dvader/notes/meeting1 . The . (period) indicates the current dir ectory as destination, and the -i ensures that if there is another file named meeting1 in the current directory, you will not overwrite it by accident. To copy a file named oldfile in the current directory to the new name newfile in the mystuff subdirectory of your home directory, enter: cp -i oldfile ~/mystuff/newfile The ~ character (tilde) is interpreted as th e path of your home directory. Note: You must have permission to read a file in order to copy it. date The date command displays the current day, date, time, and year. To see this information, enter: date df This command reports file system disk usage, (i.e., the amount of space taken up on mounted file systems). For each mounted file system, df reports the file sys tem device, the number of blocks used, the number of blocks available, and the d irectory where the file system is mounted. To find out how much disk space is used on each file system, enter the following command: df If the df command is not configured to show blocks in kilobytes by default, you can issue the following command: df -k du This command reports disk usage (i.e., the amount of space taken up by a group o f files). The du command descends all subdirectories from the directory in which you enter the command, reporting the size of their contents, and finally report

ing a total size for all the files it finds. To find out how much disk space your files take up, switch to your home director y with the cd command, and enter: du The numbers reported are the sizes of the files; on different systems, thes e sizes will be in units of either 512 byte blocks or kilobytes. To learn which is the case, use the man command, described below. On most systems, du -k will g ive sizes in kilobytes. find The find command lists all of the files within a directory and its subdirectorie s that match a set of conditions. This command is most commonly used to find all of the files that have a certain name. To find all of the files named myfile.txt in your current directory and all of i ts subdirectories, enter: find . -name myfile.txt -print To look in your current directory and its subdi rectories for all of the files that end in the extension .txt , enter: find . -name "*.txt" -print In these examples, the . (period) represents you r current directory. It can be replaced by the full pathname of another director y to search. For instance, to search for files named myfile.txt in the directory /home/user/myusername and its subdirectories, enter: find /home/user/myusername/ -name myfile.txt -print On some systems, omitting the final / (slash) after the directory name can cause find to fail to return any results. As a shortcut for searching in your home directory, enter: find "$HOME/" -name myfile.txt -print For more detailed information, see the K nowledge Base document In Unix, what is the find command, and how do I use it to search through directories for files? jobs This command reports any programs that you suspended and still have running or w aiting in the background (if you had pressed Ctrl-z to suspend an editing sessio n, for example). For a list of suspended jobs, enter: jobs Each job will be listed with a number; to resume a job, enter % (percen t sign) followed by the number of the job. To restart job number two, for exampl e, enter: %2 This command is only available in the csh, bash, tcsh, and ksh shells. kill Use this command as a last resort to destroy any jobs or programs that you suspe nded and are unable to restart. Use the jobs command to see a list of suspended jobs. To kill suspended job number three, for example, enter: kill %3 Now check the jobs command again. If the job has not been cancelled, h arsher measures may be necessary. Enter: kill -9 %3 less and more Both less and more display the contents of a file one screen at a time, waiting for you to press the Spacebar between screens. This lets you read text without i t scrolling quickly off your screen. The less utility is generally more flexible

and powerful than more, but more is available on all Unix systems while less ma y not be. To read the contents of a file named textfile in the current directory, enter: less textfile The less utility is often used for reading the output of other c ommands. For example, to read the output of the ls command one screen at a time, enter: ls -la less In both examples, you could substitute more for less with simila r results. To exit either less or more, press q . To exit less after viewing the file, press q . Note: Do not use less or more with executables (binary files), such as output fi les produced by compilers. Doing so will display garbage and may lock up your te rminal. lpr and lp These commands print a file on a printer connected to the computer network. The lpr command is used on BSD systems, and the lp command is used in System V. Both commands may be used on the UITS systems. To print a file named myfile on a printer named lp1 with lpr, enter: lpr -Plp1 myfile To print the same file to the same printer with lp, enter: lp -dlp1 myfile Note: Do not print to a printer whose name or location is unfamiliar to you. For more detailed information, see the Knowledge Base document In Unix, how do I print files and list or remove print jobs? ls This command will list the files stored in a directory. To see a brief, multi-co lumn list of the files in the current directory, enter: ls To also see "dot" files (configuration files that begin with a period, such as .login ), enter: ls -a To see the file permissions, owners, and sizes of all files, enter: ls -la If the listing is long and scrolls off your screen before you can read it, combine ls with the less utility, for example: ls -la less For more detailed information, see the Knowledge Base document I n Unix, how do I list the files in a directory? man This command displays the manual page for a particular command. If you are unsur e how to use a command or want to find out all its options, you might want to tr y using man to view the manual page. For example, to learn more about the ls command, enter: man ls To learn more about man, enter: man man If you are not sure of the exact command name, you can use man with th e -k option to help you find the command you need. To see one line summaries o f each reference page that contains the keyword you specify, enter:

man -k keyword Replace keyword in the above example with the keyword which you want to reference. Also see the Knowledge Base document In Unix, what is the ma n command, and how do I use it to read manual pages? mkdir This command will make a new subdirectory. To create a subdirectory named mystuff in the current directory, enter: mkdir mystuff To create a subdirectory named morestuff in the existing directo ry named /tmp, enter: mkdir /tmp/morestuff Note: To make a subdirectory in a particular directory, y ou must have permission to write to that directory. mv This command will move a file. You can use mv not only to change the directory l ocation of a file, but also to rename files. Unlike the cp command, mv will not preserve the original file. Note: As with the cp command, you should always use -i to make sure you do not overwrite an existing file. To rename a file named oldname in the current directory to the new name newname, enter: mv -i oldname newname To move a file named hw1 from a subdirectory named newhw to another subdirectory named oldhw (both subdirectories of the current directo ry), enter: mv -i newhw/hw1 oldhw If, in this last operation, you also wanted to give the file a new name, such as firsthw, you would enter: mv -i newhw/hw1 oldhw/firsthw ps The ps command displays information about programs (i.e., processes) that are cu rrently running. Entered without arguments, it lists basic information about int eractive processes you own. However, it also has many options for determining wh at processes to display, as well as the amount of information about each. Like l p and lpr, the options available differ between BSD and System V implementations . For example, to view detailed information about all running processes, in a BS D system, you would use ps with the following arguments: ps -alxww To display similar information in System V, use the arguments: ps -elf For more information about ps refer to the ps man page on your system. Also see the Knowledge Base document In Unix, what do the output fields of the ps command mean? pwd This command reports the current directory path. Enter the command by itself: pwd For more detailed information, see the Knowledge Base document In Unix, how do I determine my current working directory? rm

This command will remove (destroy) a file. You should enter this command with th e -i option, so that you'll be asked to confirm each file deletion. To remove a file named junk, enter: rm -i junk Note: Using rm will remove a file permanently, so be sure you really want to del ete a file before you use rm. To remove a non-empty subdirectory, rm accepts the -r option. On most systems this will prompt you to confirm the removal of each file. This behavior can be p revented by adding the -f option. To remove an entire subdirectory named oldst uff and all of its contents, enter: rm -rf oldstuff Note: Using this command will cause rm to descend into each subdirectory within the specified subdirectory and remove all files without prompting you. Use this command with caution, as it is very easy to accidently delete important files. A s a precaution, use the ls command to list the files within the subdirectory you wish to remove. To browse through a subdirectory named oldstuff, enter: ls -R oldstuff less rmdir This command will remove a subdirectory. To remove a subdirectory named oldstuff , enter: rmdir oldstuff Note: The directory you specify for removal must be empty. To c lean it out, switch to the directory and use the ls and rm commands to inspect a nd delete files. set This command displays or changes various settings and options associated with yo ur Unix session. To see the status of all settings, enter the command without options: set If the output scrolls off your screen, combine set with less: set less The syntax used for changing settings is different for the various kinds of Unix shells; see the man entries for set and the references listed at the end of thi s document for more information. vi This command starts the vi text editor. To edit a file named myfile in the curre nt directory, enter: vi myfile The vi editor works fairly differently from other text editors. If y ou have not used it before, you should probably look at a tutorial, such as the Knowledge Base document How do I use the vi text editor? Another helpful documen t for getting started with vi is A quick reference list of vi editor commands. The very least you need to know to start using vi is that in order to enter text , you need to switch the program from command mode to insert mode by pressing i . To navigate around the document with the cursor keys, you must switch back to command mode by pressing Esc. To execute any of the following commands, you mus t switch from command mode to ex mode by pressing : (the colon key): Enter w to save; wq to save and quit; q! to quit without saving. w and who The w and who commands are similar programs that list all users logged into the

computer. If you use w, you also get a list of what they are doing. If you use w ho, you also get the IP numbers or computer names of the terminals they are usin g. Also see: In Unix, how do I remove files with names that contain strange characters, such as spaces, semicolons, and backslashes? In Unix, how do I define, view, and delete aliases? In Unix, how do I change my password? In Unix, what is a symbolic link, and how do I create one? In Unix, how do I set an environment variable? In Unix, how do I change the permissions for a file? In Unix, how do I list the files in a directory? In Unix, what startup and termination files do the various shells use? In Unix, where can I get information on differences between the various shells? In Unix, how do I undelete a file? What books are available for Unix, and where can I find them? In Unix, how do I remove a directory? In Unix, how do I get a printed copy of a manual page? In Unix, how can I find the correct path to an executable file? In Unix, how do I set my default (preferred) editor? In Unix, what is the find command, and how do I use it to search through directo ries for files? For Unix, where can I find an online tutorial? In Pine, how do I access Unix commands? In Unix, how can I split large files into a number of smaller files? In Unix, how do I combine several files into a single file? At IU, what training workshops for Unix can I take? In Unix, what is chsh, and how do I use it to change my shell? This is document afsk in domain all. Last modified on September 21, 2005. Please tell us, did you find the answer to your question? Indiana University UITS Services and Support About the Knowledge Base Login Help keep the Knowledge Base up to date with suggestions, corrections, and addit ions. Copyright 1997-2005, The Trustees of Indiana University

-------------------------------------------------------------------------------Section 5: Working with Files and Directories Here is an index to the topics in this section: The UNIX filesystem structure File and directory permissions Changing directories Listing the contents of a directory Viewing the contents of a file Copying files and directories

Moving and renaming files Removing files Creating a directory Removing a directory The UNIX filesystem structure All the stored information on a UNIX computer is kept in a filesystem. Any time you interact with the UNIX shell, the shell considers you to be located somewher e within a filesystem. Although it may seem strange to be "located" somewhere in a computer's filesystem, the concept is not so different from real life. After all, you can't just be, you have to be somewhere. The place in the filesystem tr ee where you are located is called the current working directory. CONCEPT: The UNIX filesystem is heirarchical (resembling a tree structure). The tree is anchored at a place called the root, designated by a slash "/". Every it em in the UNIX filesystem tree is either a file, or a directory. A directory is like a file folder. A directory can contain files, and other directories. A dire ctory contained within another is called the child of the other. A directory in the filesystem tree may have many children, but it can only have one parent. A f ile can hold information, but cannot contain other files, or directories.

CONCEPT: To decribe a specific location in the filesystem heirarchy, you must sp ecify a "path." The path to a location can be defined as an absolute path from t he root anchor point, or as a relative path, starting from the current location. When specifying a path, you simply trace a route through the filesystem tree, l isting the sequence of directories you pass through as you go from one point to another. Each directory listed in the sequence is separated by a slash. UNIX provides the shorthand notation of "." to refer to the current location, an d ".." to refer to the parent directory. EXERCISE: Specify the absolute path to the directory named "jon" at the bottom o f the tree diagram. EXPLANATION: Since the absolute path must always begin at the root (/) directory , the path would be: /users/admin/jon EXERCISE: Specify the relative path from the directory named "student" to the di rectory named "jon" in the tree diagram. EXPLANATION: Starting from the student directory, we would first have to move up the filesystem tree (using the ".." notation) to the directory called "users" b efore we could descend to the directory called "jon". The path would be: ../admin/jon File and directory permissions CONCEPT: UNIX supports access control. Every file and directory has associated w ith it ownership, and access permissions. Furthermore, one is able to specify th ose to whom the permissions apply. Permissions are defined as read, write, and execute. The read, write, and execut e permissions are referred to as r, w, and x, respectively. Those to whom the permissions apply are the user who owns the file, those who ar e in the same group as the owner, and all others. The user, group, and other per missions are referred to as u, g, and o, respectively. A short note on groups: UNIX allows users to be placed in groups, so that the co

ntrol of access is made simpler for administrators. The meaning of file and directory permissions Read permission For a file, having read permission allows you to view the contents of the file. For a directory, having read permission allows you to list the directory's conte nts. Write permission For a file, write permission allows you to modify the contents of the file. For a directory, write permission allows you to alter the contents of the directory, i.e., to add or delete files. Execute permission For a file, execute permission allows you to run the file, if it is an executabl e program, or script. Note that file execute permission is irrelevant for nonexe cutable files. For a directory, execute permission allows you to cd to the direc tory, and make it your current working directory. Viewing permissions To see the permissions on a file, use the ls command, with the -l option. EXAMPLE: Execute the command ls -l /etc/passwd to view the information on the system password database. The output should look similar to this: -rw-r--r-- 1 root sys 41002 Apr 17 12:05 /etc/passwd The first 10 characters describe the access permissions. The first dash indicate s the type of file (d for directory, s for special file, - for a regular file). The next three characters ("rw-") describe the permissions of the owner of the f ile: read and write, but no execute. The next three characters ("r--") describe the permissions for those in the same group as the owner: read, no write, no exe cute. The next three characters describe the permissions for all others: read, n o write, no execute. Setting permissions UNIX allows you to set the permissions on files that you own. The command to cha nge the file permission mode is chmod. Chmod requires you to specify the new per missions you want, and specify the file or directory you want the changes applie d to. To set file permissions, you may use to the "rwx" notation to specify the type o f permissions, and the "ugo" notation to specify those the permissions apply to. To define the kind of change you want to make to the permissions, use the plus s ign (+) to add a permission, the minus sign (-) to remove a permission, and the equal sign (=) to set a permission directly. EXAMPLE: Type the command chmod g=rw- ~/.shrc to change the file permissions on the file .shrc, in your home directory. Specif ically, you are specifying group read access and write access, with no execute a ccess. EXERCISE: Change the permissions on the .shrc file in your home directory so tha t group and others have read permission only.

EXPLANATION: Typing the command chmod go=r-- ~/.shrc would accomplish the task. Changing Directories In UNIX, your location in the filesystem heirarchy is known as your "current wor king directory." When you log in, you are automatically placed in your "home dir ectory." To see where you are, type the command pwd which stands for "print working directory." To change your location in the filesystem heirarchy, use the cd (change director y) command, followed by an argument defining where you want to go. The argument can be either an absolute path to the destination, or a relative path. EXAMPLE: Type the command cd /tmp to go to the /tmp directory. You can type pwd to confirm that you're actually there. If you type the cd command without an argument, the shell will place you in your home directory. EXERCISE: Type the command pwd and note the result. Then type cd .. to the shell. Type pwd again to see where you ended up. EXPLANATION: The "cd .." command should have moved you up one level in the direc tory tree, because ".." is UNIX shorthand for the parent directory. The result o f the second "pwd" command should be the same as the first, with the last direct ory in the path omitted. Listing the contents of a directory The ls command allows you to see the contents of a directory, and to view basic information (like size, ownership, and access permissions) about files and direc tories. The ls command has numerous options, so see the manual page on ls (type man ls) for a complete listing. The ls command also accepts one or more argument s. The arguments can be directories, or files. EXAMPLE: Type the command ls -lr /etc/i* to the UNIX shell. In the example, the "l" and "r" options of the ls command are invoked together. Some commands permit you to group options in that way, and some commands require the options to be named separately, e.g., ls -l -r. The l option calls for a lo ng output, and the r option causes ls to operate recursively, moving down direct ory trees. The last part of the example, "/etc/i*", directs the ls command to list files an d directories in the /etc directory, that begin with the letter i. The wildcard character, "*", matches any character(s). EXERCISE: Type the command

ls -m /etc/i*g to the shell. How did the shell respond, and why? EXPLANATION: The shell responded by printing all the entries in the /etc directo ry that start with the letter i, and end with the letter g. The -m option causes the output to be streamed into a single line. See the manual page for ls to get a complete description of the ls command's options. EXERCISE: Find the permissions on your home directory. EXPLANATION: There are many ways to accomplish this. You could type cd to get to your home directory, and then type ls -la The -a option instructs the ls command to list all files, including those that s tart with the period character. The directory permissions are listed next to the "." symbol. Remember that "." is UNIX shorthand for the current working directo ry. Viewing the contents of a file CONCEPT: Text files are intended for direct viewing, and other files are intende d for computer interpretation. The UNIX file command allows you to determine whether an unknown file is in text format, suitable for direct viewing. EXERCISE: Type the command file /bin/sh to see what kind of file the shell is. EXPLANATION: The shell is a shared executable, indicating that the file contains binary instructions to be executed by the computer. The cat command The cat command concatenates files and sends them to the screen. You can specify one or more files as arguments. Cat makes no attempt to format the text in any way, and long output may scroll off the screen before you can read it. EXAMPLE: Send the contents of your .profile file to the screen by typing cat ~/.profile to the shell. The tilde character (~) is UNIX shorthand for your home directory. The more The more orward a pressing command command displays a text file, one screenful at a time. You can scroll f line at a time by pressing the return key, or a screenful at a time by the spacebar. You can quit at any time by pressing the q key.

EXAMPLE: Type more /etc/rc to the shell. Scroll down by pressing return, and by pressing the spacebar. Stop the more command from displaying the rest of the file by typing q. The head and tail commands The head command allows you to see the top part of a file. You may specify the n umber of lines you want, or default to ten lines. EXAMPLE: Type head -15 /etc/rc

to see the first fifteen lines of the /etc/rc file. The tail command works like head, except that it shows the last lines of of file . EXAMPLE: Type tail /etc/rc to see the last ten lines of the file /etc/rc. Because we did not specify the nu mber of lines as an option, the tail command defaulted to ten lines. Copying files and directories The UNIX command to copy a file or directory is cp. The basic cp command syntax is cp source destination. EXAMPLE: The command cp ~/.profile ~/pcopy makes a copy of your .profile file, and stores it in a file called "pcopy" in yo ur home directory. EXERCISE: Describe the permissions necessary to successfully execute the command in the previous example. EXPLANATION: To copy the .profile file, one must have read permission on the fil e. To create the new file called pcopy, one must have write permission in the di rectory where the file will be created. Moving and renaming files The UNIX mv command moves files and directories. You can move a file to a differ ent location in the filesystem, or change the name by moving the file within the current location. EXAMPLE: The command mv ~/pcopy ~/qcopy takes the pcopy file you created in the cp exercise, and renames it "qcopy". Removing files The rm command is used for removing files and directories. The syntax of the rm command is rm filename. You may include many filenames on the command line. EXAMPLE: Remove the the shrccopy file that you placed in your home directory in the section on moving files by typing rm ~/.shrccopy Creating a directory The UNIX mkdir command is used to make directories. The basic syntax is mkdir di rectoryname. If you do not specify the place where you want the directory create d (by giving a path as part of the directory name), the shell assumes that you w ant the new directory placed within the current working directory. EXAMPLE: Create a directory called foo within your home directory by typing mkdir ~/foo EXERCISE: Create a directory called bar, within the directory called foo, within your home directory. EXPLANATION: Once the foo directory is created, you could just type mkdir ~/foo/bar Alternately, you could type

cd ~/foo; mkdir bar In the second solution, two UNIX commands are given, separated by a semicolon. T he first part of the command makes foo the current working directory. The second part of the command creates the bar directory in the current working directory. Removing a directory The UNIX rmdir command removes a directory from the filesystem tree. The rmdir c ommand does not work unless the directory to be removed is completely empty. The rm command, used with the -r option can also be used to remove directories. The rm -r command will first remove the contents of the directory, and then remo ve the directory itself. EXERCISE: Describe how to remove the "foo" directory you created, using both rmd ir, and rm with the -r option. EXPLANATION: You could enter the commands rmdir ~/foo/bar; rmdir ~/foo to accomplish the task with the rmdir command. Note that you have to rmdir the b ar subdirectory bfore you can rmdir the foo directory. Alternately, you could re move the foo directory with the command rm -r ~/foo --------------------------------------------------------------------------------

Vous aimerez peut-être aussi