This is a guide to some basic UNIX commands. It is intended for people with little or no experience with UNIX. It will teach you how to manipulate files and directories, communicate with other UNIX users, as well as some other useful and fun stuff that UNIX can do. Some of the commands are local to Brown, while others are supported on all UNIX systems.
*note: The man page links are only available from within the
Brown cs department. If you are local and still getting errors, use
http://localhost/whatever instead of http://www.cs.brown.edu/whatever.
xterm -e /bin/login &
. This provides a new shell with a login prompt which allows
someone to login to the computer.
* | match any characters in a filename (wild-card) |
| | take output from one command and use it as input for a second command (pipe) |
> | redirect output (over-writes) |
>> | append output |
& | run process in the background |
finger @cslab0a
will return all the users logged on to cslab0a. Typing finger
by itself will tell you who is logged on to the machine you are on.
cd u/ck
and I will be in /u/ck, ck's home directory, since it
will change directories relative to my current path. If I codefix the
directory name with a /, it will jump to an absolute location so typing
cd /u/ljc
from /u/ck will put you into /u/ljc. Also, the
directory ".." is one level up in the heirarchy, so from /u/adt typing
cd ..
will move you up one directory into /u.
So, for example, if i want to flag filenames when using the ls command, I can type ls -F.
Using more, press the return key to view the next line of text, the spacebar to read the next page of text, q to quit, and / to search.
You can use the same commands in less, but in addition you can use the arrow keys to navigate by line, and u to move up a page. A useful option is -N, which numbers the line in the files.
To use more or less, type more or less and the name of the file you want to read. Type any option you want to use before the filename. As with any command in this guide, for more options or more information about a command, see the man pages.
mv foo foo.html
. Now if we want to move
foo.html to dmb's home directory, we type mv foo.html /u/dmb
.
cp foo foo.html
. Likewise, we can copy a file
into another directory: cp foo.html /u/dmb
. If we want
to copy a file from a different directory into a current directory, we
can use a '.' to mean the current directory. So to copy foo.html from
dmb's home directory into the current directory, type cp
/u/dmb/foo.html .
rm
*.html
removes all files whose name ends in ".html". Likewise,
typing rm *
removes all the contents of a directory.
However, to recursively remove the contents of all subdirectories, you
must use the -r option. The command can also be used to remove a
not-empty directory and its contents by specifying a directory name. Be
warned! This is a dangerous command to use, because if the directory contains
files, you may be unknowingly removing them when you remove the entire
directory.
mkdir JavaWork
.
pwd
while I am in ljc's home
directory, UNIX responds /home/ljc
.
chmod a+r foo.html
chmod g+rw foo.html
chmod o-x foo.html
chgrp cs015 foo.html
.
grep UNIX foo.html
.
cat a b > foo.html
will
create a file, foo.html that consists of the contents of a followed by the
contents of b. If we then type cat c >> foo.html
foo.html will contain the contents of a then b then c. Another
redirection operator, called pipe (the '|' key), takes the output of one
operation and uses it as the input to another operation. So cat
foo.html | mail dmb
will take the output from foo. html and use it
as the input for and e-mail to dmb.
-<the number of lines>
. For
example, head -20
will print out the first 20 lines of
a file.
ln foo.html foo
, foo becomes a psuedonym for foo.html.
If foo is an already existing file, it is overwritten. If foo is a
directory, however, a link named foo.html is created in foo. The
-s option creates a symbolic link, which lets
you link across file systems and also lets you see the name of the
link when you run ls -l.
zwgc -ttymode
.
talk dmb@cslab0a
. The recipient of the
request is then prompted for a response.
mesg n
or mesg -n
forbids messages, while mesg
y
or mesg -y
allows messages.
kill
<PID>
to stop the process.
back to the top
lpr -Pcis foo.html
.
lpq -Pcis
.
lprm
787
to remove the job from the printer queue. Using the
command alone removes the first of your jobs in the printer queue.
pr -f
foo1 foo2 foo3 | lpr
. The pipe (|)
operation takes the output
from the first command and uses it as the input for the second
command. The pr command is basically used to apply options to, and
then sent to the printer by piping the output to the lpr command. For more options, see
the man pages.
su - dmb
, the computer will go through
the entire login sequence, where as without the dash, the environment
will remain unchanged.
rsh cslab0a -l dmb
will allow dmb to remotely log on to cslab0a from the computer
she is on. She will have to type her password at the prompt for this
to be successful, however. If dmb is already logged on the computer
she is trying to rsh another machine from, she does not have to use
the -l option. She can simply type rsh cslab0a
.
rlogin
cslab0a -l dmb
and type her password at the prompt. To
remotely log on from her own account to another machine she would
simply need to type rlogin cslab0a
.
xhost + <name>
to add permission, or xhost - <name>
to
remove a permission. Using xhost + without a name allows anyone to
use your xserver. The command xhost + localhost
can be
used to allow any user logged on to your machine to use the display.
setenv DISPLAY localhost:0
cal 12 1999
.
which z
, the command returns z:
aliased to zwrite
.
loc -g cs015ta
.