Basic UNIX Commands
Basic UNIX Commands
1/4 mally.stanford.edu/sr/computing/basic-unix.html
Basic UNIX commands
Note: not all oI these are actually part oI UNIX itselI, and you may not Iind them on all UNIX machines. But
they can all be used on turing in essentially the same way, by typing the command and hitting return. Note that
some oI these commands are diIIerent on non-Solaris machines - see SunOS diIIerences.
II 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 Iiles
ls -l --- lists your Iiles in 'long Iormat', which contains lots oI useIul inIormation, e.g. the exact size oI the
Iile, who owns the Iile and who has the right to look at it, and when it was last modiIied.
ls -a --- lists all Iiles, including the ones whose Iilenames begin in a dot, which you do not always want to
see.
There are many more options, Ior example to list Iiles by size, by date, recursively etc.
more filename --- shows the Iirst part oI a Iile, just as much as will Iit on one screen. Just hit the space
bar to see more or q to quit. You can use /paen to search Ior a pattern.
emacs filename --- is an editor that lets you create and edit a Iile. See the emacs page.
mv filename1 filename2 --- moves a Iile (i.e. gives it a diIIerent name, or moves it into a diIIerent
directory (see below)
cp filename1 filename2 --- copies a Iile
rm filename --- removes a Iile. It is wise to use the option rm -i, which will ask you Ior conIirmation
beIore actually deleting anything. You can make this your deIault by making an alias in your .cshrc Iile.
diff filename1 filename2 --- compares Iiles, and shows where they diIIer
wc filename --- tells you how many lines, words, and characters there are in a Iile
chmod opion filename --- lets you change the read, write, and execute permissions on your Iiles. The
deIault 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 Iile readable Ior everyone, and chmod o-r
filename will make it unreadable Ior others again. Note that Ior someone to be able to actually look at
the Iile the directories it is in need to be at least executable. See help protection Ior more details.
File Compression
gzip filename --- compresses Iiles, so that they take up much less space. Usually text Iiles
compress to about halI their original size, but it depends very much on the size oI the Iile and the
nature oI the contents. There are other tools Ior this purpose, too (e.g. compress), but gzip usually
gives the highest compression rate. Gzip produces Iiles with the ending '.gz' appended to the original
Iilename.
gunzip filename --- uncompresses Iiles compressed by gzip.
gzcat filename --- lets you look at a gzipped Iile without actually having to gunzip it (same as
gunzip -c). You can even print it directly, using gzcat filename lpr
printing
lpr filename --- print. Use the -P option to speciIy the printer name iI you want to use a printer
other than your deIault printer. For example, iI you want to print double-sided, use 'lpr -Pvalkyr-d',
1/31/12 Basic UNIX commands
2/4 mally.stanford.edu/sr/computing/basic-unix.html
or iI you're at CSLI, you may want to use 'lpr -Pcord115-d'. See 'help printers' Ior more
inIormation about printers and their locations.
lpq --- check out the printer queue, e.g. to get the number needed Ior removal, or to see how many
other Iiles will be printed beIore yours will come out
lprm jobnmbe --- remove something Irom the printer queue. You can Iind the job number by
using lpq. Theoretically you also have to speciIy a printer name, but this isn't necessary as long as
you use your deIault printer in the department.
genscript --- converts plain text Iiles into postscript Ior printing, and gives you some options Ior
Iormatting. Consider making an alias like alias ecop 'genscript -2 -r \!* lpr -h -Pvalkyr' to print
two pages on one piece oI paper.
dvips filename --- print .dvi Iiles (i.e. Iiles produced by LaTeX). You can use dviselect to print
only selected pages. See the LaTeX page Ior more inIormation about how to save paper when
printing draIts.
Directories
Directories, like Iolders on a Macintosh, are used to group Iiles together in a hierarchical structure.
mkdir diname --- make a new directory
cd diname --- change directory. You basically 'go' to another directory, and you will see the Iiles 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 arguments. 'cd ..' will get you one level up Irom your current position. You don't have
to walk along step by step - you can make big leaps or avoid walking around by speciIying pathnames.
pwd --- tells you where you currently are.
Finding things
ff --- Iind Iiles anywhere on the system. This can be extremely useIul iI you've Iorgotten in which directory
you put a Iile, but do remember the name. In Iact, iI you use ff -p you don't even need the Iull name, just
the beginning. This can also be useIul Ior Iinding other things on the system, e.g. documentation.
grep ing filename() --- looks Ior the string in the Iiles. This can be useIul a lot oI purposes, e.g.
Iinding the right Iile among many, Iiguring out which is the right version oI something, and even doing
serious corpus work. grep comes in several varieties (grep, egrep, and fgrep) and has a lot oI very
Ilexible options. Check out the man pages iI this sounds good to you.
About other people
w --- tells you who's logged in, and what they're doing. Especially useIul: the 'idle' part. This allows you to
see whether they're actually sitting there typing away at their keyboards right at the moment.
who --- tells you who's logged on, and where they're coming Irom. UseIul iI you're looking Ior someone
who's actually physically in the same building as you, or in some other particular location.
finger ename --- gives you lots oI inIormation about that user, e.g. when they last read their mail and
whether they're logged in. OIten people put other practical inIormation, such as phone numbers and
addresses, in a Iile called .plan. This inIormation is also displayed by 'Iinger'.
last -1 ename --- tells you when the user last logged on and oII and Irom where. Without any options,
1/31/12 Basic UNIX commands
3/4 mally.stanford.edu/sr/computing/basic-unix.html
last will give you a list oI 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, oI course, read them). It's not the
only mailer you can use, but the one we recommend. See the elm page, and Iind out about the
departmental mailing lists (which you can also Iind in /user/linguistics/helpIile).
About our (electronic) self
whoami --- returns your username. Sounds useless, but isn't. You may need to Iind out who it is who
Iorgot to log out somewhere, and make sure *you* have logged out.
finger & .plan Iiles
oI course you can Iinger yourselI, too. That can be useIul e.g. as a quick check whether you got new mail.
Try to create a useIul .plan Iile soon. Look at other people's .plan Iiles Ior ideas. The Iile needs to be
readable Ior everyone in order to be visible through 'Iinger'. Do 'chmod ar .plan' iI necessary. You
should realize that this inIormation is accessible Irom anywhere in the world, not just to other people on
turing.
passwd --- lets you change your password, which you should do regularly (at least once a year). See the
LRB guide and/or look at help password.
ps -u ourusername --- lists your processes. Contains lots oI inIormation about them, including the
process ID, which you need iI you have to kill a process. Normally, when you have been kicked out oI a
dialin session or have otherwise managed to get yourselI disconnected abruptly, this list will contain the
processes you need to kill. Those may include the shell (tcsh or whatever you're using), and anything you
were running, Ior example emacs or elm. Be careIul not to kill your current shell - the one with the number
closer to the one oI the ps command you're currently running. But iI it happens, don't panic. Just try again
:) II you're using an X-display you may have to kill some X processes beIore you can start 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 Ior your own processes, oI
course. Get the ID by using ps. II the process doesn't 'die' properly, use the option -9. But attempt
without that option Iirst, because it doesn't give the process a chance to Iinish possibly important business
beIore dying. You may need to kill processes Ior example iI your modem connection was 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 Iiles), 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 you have leIt to sort them out (by deleting or gzipping some, or
moving them to your own computer).
du filename --- shows the disk usage oI the Iiles and directories in fieae (without argument the
current directory is used). du -s gives only a total.
last ourusername --- lists your last logins. Can be a useIul memory aid Ior when you were where, how
long you've been working Ior, and keeping track oI your phonebill iI you're making a non-local phonecall
Ior dialling in.
Connecting to the outside world
nn --- allows you to read news. It will Iirst let you read the news local to turing, and then the remote
1/31/12 Basic UNIX commands
4/4 mally.stanford.edu/sr/computing/basic-unix.html
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 \tty{:man, then \tty{=.*, then \tty{Z, then hit the space bar to step
through the 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 an 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 (temporarily) 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
machine, and put for putting them there (mget and mput let you specify more than one file at once).
Sounds straightforward, but be sure not to confuse the two, especially when your physical location doesn't
correspond to the direction of the ftp connection you're making. ftp just overwrites files with the same
filename. If you're transferring anything other than ASCII text, use binary mode.
ln --- lets you browse the web from an ordinary terminal. Of course you can see 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 .stanford.edu part of the URL when connecting to Stanford URLs.
Type H at any time to learn more about ln, and Q to exit.
Miscellaneous tools
ebster ord --- looks up the word in an electronic version of Webster's dictionary 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 that 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