Sei sulla pagina 1di 25

Useful UNIX Commands

Useful UNIX Commands

The following is a list of some of the more important and useful commands in Unix (specific to HPUX)
Remember that the man command can be used to find out the specific usage of any of these.

Essentials

• logout - use this command when you are done, always


• man - use the command `man command' to learn about a command.

Files and Directories

• cd - change directory
• pwd - print working directory (the directory you are in)
• rmdir - remove directory (the directory must be empty)
• mkdir - make a new directory
• rm - remove a file or directory
• ls - list files
• cp - copy a file
• mv - move a file (destroys original)
• less - view a text file
• cat - prints the contents of a file on the screen
• touch - create an empty file
• gzip and gunzip - compression and decompression
• tar - Tape Archive. Now used to store directory trees as a single file for easy transfer. See the -xvf
and -cvf options in the man page
• uudecode and uuencode decode and encode binary files as text files for transfers

System Status

• date - displays the current date and time


• du - displays amount of disk space in 512byte blocks ('du -s' gives the summary for a directory)
• quota -v - displays disk limits and amount currently in use
• ps - display running processes ('ps -ef | grep username' gives all the processes owned by a
particular user)
• who - display who is on the machine and where they are connected from
• w - display who is on and what they are doing
• who - display who is on and where they are on from
• jobs - display the jobs you own
• uptime - display time, number of users, and load averages
• loads - a local script to show the loads on all the HP700s
• renice - alters priority of a running process. You should renice long simulations so you don't hog
processor cycles.

Networking

• ssh - open an encrypted connection with a host


• telnet - open a remote session with host
• rlogin - open a remote session with host
• ftp - File Transfer Protocol: send and receive files betweem machines
• ping - check to make sure a remote machine is reachable
• finger - show information about a person on a system or whoever is on the remote system WWW
version

Editors and Text Processors

• vi - Visual Editor. Great stuff


• pico - Easy to use editor
• grep - searches a file for a pattern
• a2ps - (not currently availible) allows the formatting of text into a multi-columned format

Printing

Please see the printing one-pager for details about printing.

• lp - print the specified file. Common usage: 'lp -dhpps file.ps'


• lpstat - tells you infomation about current print jobs
• cancel - cancel a print job. Common usage: 'cancel hpps-###'

That should be a good start on the commands that you need. Take a look at the software available on the
700s as well. Remember, if you don't know, ask questions. Most people here in ECE are willing to help
other people.

Common UNIX Commands

This document presents a brief description of commonly used UNIX commands. The list is a small subset
of the available commands and utilities. For more information on these commands and others not listed
here, consult the online manual pages (see the man command) which are accessible from WWW through
our man pages gateway or talk to a member of the Informatics Core staff.
Note: Enter the commands below exactly as shown (including spaces and upper- or lowercase). Arguments
or parameters to the commands are shown in italics and should be replaced with your own values at the
time that you execute the command (e.g. the name of a file is an argument to the cat command rather than
the word, file).
alias alias-term command-string
The alias built-in shell command allows the entering of shorter or easy-to-remember names to
execute longer or hard-to-remember commands. The command is entered to set alias-term equal
to command-string. If command-string has spaces in it, single quotes should be around the string.
For example, entering alias dir 'ls -al' will allow ls -al to be executed whenever the dir command
is entered (thus easing the transition to UNIX for the MS-DOS users). Each user can put these
alias commands in their .cshrc file to have the aliases automatically set each time the user logs in.
Entering alias by itself will list all the aliases currently set for the user.
cat file
The cat command displays the contents of the file named by file. If the file is large, all but the last
screenfull of lines will scroll off the screen too quickly to read. To display the file a screenful at a
time, use the more command.
chdir directory
cd directory
The chdir command moves you (changes your current working directory) to directory. Entering
cd without the directory argument will move you to your home directory.
Examples:
cd /usr/hgp
moves you to the hgp directory inside of the usr directory.
cd ..
moves you to the parent directory of your current directory.
chmod permissions path
The chmod command changes the access permission associated with a file or directory ("file" will
be used here to refer to either a file or a directory).
Each file has three types of access: read (r), write (w) and execute (x). In a ls -al file listing, the
abbreviations appear in the columns on the left. To see the contents of a file, the file must have
read (r) permission. To change the contents of a file (e.g. saving changes after editing), write (r)
permission must be enabled. To execute a command by entering the name at the UNIX prompt,
the file must have execute (x) permission. To access a directory, the execute (x) permission must
be granted for that directory. If a given type of access is not permitted, it will show up as a dash (-)
rather than r, w or x in the ls -al listing.
The access to a file can be controlled separately for three sets of users: the owner of the file (u), a
limited group of users (g), and everyone on the system (o). In a ls -al file listing, the first three
columns (starting in column two of the listing) are the r, w and x access allowed for the owner, the
second three are the access allowed for the group and the third three are the access allowed for
everyone else.
Permissions can be specified in numeric format or using the abbreviations above. For the numeric
format, three numbers are specified where each number represents the access granted for one of
the three sets of users. Each permission number is determined by adding up the value associated
with each type of access: r = 4, w = 2 and x = 1. For example, the value 7 grants all access, the
value 5 grants only read and execute access but not write access and the value 0 does not allow
any access to the file. The numeric access specification is an absolute one; all three types of access
for all three sets of users are reset according to the new permissions.
Examples:
chmod 640 .cshrc
grants read and write permission (6) to the owner of the file, read-only permission to the group,
and no permissions for everyone else. The would appear in a file listing as rw-r-----.
chmod 777 .
grants all access to the owner, group, and everyone for the current working directory.
The permissions can also be specified using abbreviations rather than numbers. Using this method,
some of the permissions can be changed without affecting others. The permissions format is <u, g
or o> <+ or -> <r, w or x>. The + adds the access indicated to the file without affecting the other
permissions. The - removes the access from the file.
Examples:
chmod u+rw report
adds read and write permission to the file, report, for the owner of the file. Access for the group
and everyone is unchanged.
chmod +x somecommand
adds execute permission to the file, somecommand, for all three sets of users.
chmod go-rwx private.file
removes all access to the file, private.file, for the group and everyone and leaves the owner's
access unchanged.
chown username path
The chown command changes the ownership of the file or directory, path, to user, username. Both
the user-ownership and the group-ownership may be changed at once by specifying user.group for
the username parameter. One must have root privilages to do this so this command will not be too
useful for most users. If you really want to own someone else's file that you have read-access to,
make a copy of the file using the command, cp.
cp file1 file2
The cp command creates an identical copy of the file, file1, and names the copy, file2. Note that
the ownership of file2 will be set to whoever does the cp command.
date
The date command displays the current date and time. Use date -u to see the time in Greenwich
Mean Time (GMT), universal time.
diff file1 file2
The diff command compares the contents of two text files and displays the differences. The lines
preceded with < are from file1. The lines preceded by > are from file2. Each section of differences
is separated by ---.
enscript textfile
The enscript command converts the file, textfile, (that you might otherwise print with lpr) to
Postscript and then prints it. More importantly, enscript allows the printing of two text pages
reduced onto one piece of paper with page numbers and a title. For example, enscript -2rG
lots.of.docs prints the file, lots.of.docs, in landscape mode, two pages per printout, with fancy
headers.
exit
The exit command terminates the current UNIX shell. If you started this UNIX session (shell)
with either the rlogin, su command from within another session, exit returns you to your previous
session. If not, exit usually just closes your window (either an xterm window or terminal program
window) or returns you to a login: prompt.
finger name@address
The finger command displays information about user accounts with names (usernames or proper
names) matching name on the machine identified by address. The argument name may be a
known username or a first or last proper name without any spaces although this varies from
machine to machine. When fingering @med.umich.edu, first and last name separated by a period
may be used, e.g. finger john.smith@med.umich.edu.
The finger command may not work if the remote machine is not a UNIX machine (although most
multi-user machines have finger capability these days). If only the @address portion of the
argument is used, all of the users currently logged into the remote machine may be displayed. If no
argument is specified, all of the users currently logged into your machine are shown (see also the
who command).
An electronic mail address can often be verified or determined using the finger command. For
example, finger john@med.umich.edu returns a list of all Johns, Johnsons, and other variations
in the UMMC network. finger a.smith@med.umich.edu gives all the people with an a in their
first name and Smith in their last name.
grep pattern file
The grep command searches one or more files, specified by file, for the text string specified by
pattern. For example, grep 'dna' seqfile1 will list all lines found in the file, seqfile1, which
contain the text "dna". Grep is usually used to search for text in several files at once, e.g. grep
'dna' * will perform the same search on all the files in your current directory (see wildcard
characters for an explanation of *).
head file
tail file
The head and tail commands list the first (head) or last (tail) ten lines of your file. The number of
lines listed may be varied by including -n number-of-lines option. For example, head -n 50
report1 will list the first fifty lines of the file report1.
hgppasswd
See passwd.
kill id-number
The kill command terminates the process with the id, id-number. The process id can be
determined with the ps command. Generally, the kill command is the last method tried to
terminate a running program. If a normal kill (a kill without any kill-level option specified before
the id-number) does not remove the process, including the -9 option will usually annihilate it
(unless it is a zombie process -- in which case it doesn't exist so it can't be killed (confused yet?))
e.g. kill -9 18201 is a "sure kill" of process number 18201.
lpr textfile
The lpr command will print the file, textfile on the default printer. A specific printer may be
specified with the -P option. For example, lpr -Phgp2 sequence sends the file, sequence, to the
printer named "hgp2".
HGP UNIX Special Case: We have two UNIX printers (whose name can be specified with the
-Pname option of the print commands). Printer hgp1 is in 2570 MSRB II, and hgp2 is in 2568
MSRB II.
lpq
The lpq command displays the status of jobs (documents) in the print queue (waiting to print). The
-Pprinter option specifies which printer queue to check. For example, lpq -Phgp2 checks the
status of documents waiting to print on the printer named "hgp2".
lprm job-number
The lprm command removes the waiting document, job-number, from the print queue. The value
for job-number can be obtained from the lpq command. If the job is to be removed from a print
queue other than the default, the -Pprinter parameter is used to specify the print queue (just as
with lpr and lpq). Note that each user may only remove print jobs that their own print jobs.
ls pattern
The ls command lists the files and directories in a directory. If pattern is the name of a file, only
that file (or files if wildcards are used) is listed. If pattern is a directory name, the contents of that
directory are listed. If pattern is omitted, all the files and directories in your current directory are
listed. The output of the ls command may be piped into the more command to pause the listing
after each screenful of text (e.g. ls -al | more).
Here are a few of the options for the ls command (for a complete list, see the ls man page):
-a
lists all files in the current directory. Without this option, filenames that begin with a period (such
as .cshrc, .login, and ..) are not shown).
-l
lists the filenames in long format. This format includes the protections (changable with chmod) on
each file and the owner of the file.
-g
adds the group ownership of the file to the information displayed with the -l option described
above.
-F
highlights directories with a trailing /, executable files with a trailing * and symbolic links with a
trailing @ in a listing.
Examples:
ls
lists every file (except those filenames that begin with a period) in in the current directory.
ls -al /bin
lists all files in the /bin directory in the long format.
ls -laFg
lists all files in the current directory in long format (including group ownership), highlighting
directories, executable files and symbolic links.
man command
The man command displays the standard UNIX manual page for the command you specify. These
pages may be somewhat cryptic for some users but generally tell you all you would ever want to
know about the command. You may search our man pages now through our man pages gateway.
md dir1
mkdir dir1
The mkdir command creates the directory, dir1, within your current directory (unless the
specification of dir1 begins with a /).
HGP UNIX Special Case: md is an alias for mkdir on our system.
more file1
The more command displays the contents of the text file, file1, a screenful at a time, pausing at the
end of each screen until the user presses one of a few special keys. When the display pauses, the
user may press:
• <SPACE> to display to the next page of text,
• <ENTER> to display only one more line of text,
• / followed by a word and the <ENTER> to search for that word in the remaining
text of the file,
• ? to see all the operations available in more,
• q or CONTROL-C to quit displaying the file and return to the command
prompt.

more may also be used at the end of a "pipe" to cause the output from another command to be
paused a screen at a time. This is useful when a UNIX command produces a lot of output too fast
for the user to see before the output scrolls off the screen. For example, the ls -al command often
produces long directory listings which are better viewed a screen at a time by entering ls -al |
more.
mv name1 name2
The mv command moves and/or renames the file or directory, name1. If name2 is an existing
directory, name1 will be moved (not copied) into the directory, name2. If name2 is not an existing
directory, name1 (whether it be a file or directory) will simply be renamed into name2. It is
possible to move and rename name1 at the same time if name2 is a new name withing an existing
directory. Any file file already existing with name2 will be overwritten by the renaming or moving
of name1 unless mv -i is used, which asks the user for confirmation of destruction of existing files.
HGP UNIX Special Cases: mv is an alias for mv -i on the HGP systems so using the -i option is
not necessary unless mv has been unaliased or aliased to something new.
passwd
hgppasswd
The passwd command changes your UNIX login password. After entering the command passwd,
you will be asked to enter your old password, then the new password that you want to change to,
and then the same new password again. You are asked to enter the new password twice to assure
that you have typed it correctly. None of the passwords you enter will be displayed on the screen
as you type them.
HGP UNIX Special Cases:

• The passwd command only affects your UNIX login password and does not
change your Sybase database login password.
• hgppasswd allows to to remotely set your passwd on
mendel.hgp.med.umich.edu without having to first login to that machine if you are
currently logged into another HGP Sun workstation. Why would you want to do this?
The passwords on mendel are copied out to all the other Suns twice a day. If you changed
your password on any machine other than mendel using the passwd command, it will be
overwritten with your password from mendel within twelve hours, effectively reverting
back to your old password. Therefore, any password changes must be made by running
the passwd command while logged into mendel (to log into mendel from any other HGP
Sun, see the rlogin command) or by using the hgppasswd command while logged into
any other machine. Note that running hgppasswd from a machine other than mendel does
not set your new password on your current machine immeadiately. You may additionally
run the passwd command on the local machine to make the change immeadiately for that
machine.

ps
The ps command displays a list of the processes currently running on the machine that you are
logged into. If no arguments are entered with the ps command, only the "important" processes,
that you own (i.e. that you are running) are displayed. The -a option includes processes owned by
others in the list. The -g option includes all processes, not just "important" processes. The -u
option provides more information for each processes than is printed by default.
Examples (note that the dash in a ps option is not required):
ps g
List all the processes running that you own (minimal information).
ps ug
List all the processes running that you own (lots of information).
ps ag
List all the processes running on this machine no matter who owns them.
To terminate a process, see the kill command.
pwd
The pwd command displays the full path of your current working directory. In other words, it tells
you what directory you are in.
rlogin address
The rlogin command logs into another machine specified by address. The -l username option
allows you to specify a username to attempt the remote login with. If this option is omitted, your
current username is used by default. Examples:
rlogin mendel logs you into the machine named mendel with your
current username
rlogin mendel -l smith logs you into the machine named mendel as user
smith (of course, you must know smith's
password).
You can close the connection from the remote machine by entering the command, exit.
rm yourfile
The rm command removes the file, yourfile, permanently from the filesystem. This cannot be
undone so be careful when using wildcards in the file specification. Use rm -i to force user-
confirmation of each file to be removed. Using rm -r somedir will remove the subdirectory
somedir as well as all the subdirectories and files within that subdirectory.
HGP UNIX Special Cases: rm is an alias for rm -i on the HGP systems so using the -i option is
not necessary unless rm has been unaliased or aliased to something new.
rmdir dir1
The rmdir command deletes the empty subdirectory, dir1. To delete non-empty subdirectories,
see rm -r.
su username
The su command allows a user to assume the identity and permissions of another user, username
(provided that the password for username is known). The su session is ending by entering the
command, exit.
tail file
See head.
telnet address
See telnet as listed in the glossary for now.
wc yourfile
The wc command counts the number of words or characters and lines in your file. If the -l option
is used, only the number of lines is counted.
who
The who command displays a list of who is logged on to the system and where they are logged on
from. See also finger.

Unix Command Summary

See the Unix tutorial for a leisurely, self-paced introduction on how to use the commands listed below. For
more documentation on a command, consult a good book, or use the man pages. For example, for more
information on grep, use the command man grep.

Contents

• cat --- for creating and displaying short files


• chmod --- change permissions
• cd --- change directory
• cp --- for copying files
• date --- display date
• echo --- echo argument
• ftp --- connect to a remote machine to download or upload files
• grep --- search file
• head --- display first part of file
• ls --- see what files you have
• lpr --- standard print command (see also print )
• more --- use to read files
• mkdir --- create directory
• mv --- for moving and renaming files
• ncftp --- especially good for downloading files via anonymous ftp.
• print --- custom print command (see also lpr )
• pwd --- find out what directory you are in
• rm --- remove a file
• rmdir --- remove directory
• rsh --- remote shell
• setenv --- set an environment variable
• sort --- sort file
• tail --- display last part of file
• tar --- create an archive, add or extract files
• telnet --- log in to another machine
• wc --- count characters, words, lines

cat

This is one of the most flexible Unix commands. We can use to create, view and concatenate files. For our
first example we create a three-item English-Spanish dictionary in a file called "dict."
% cat >dict
red rojo
green verde
blue azul
<control-D>
%
<control-D> stands for "hold the control key down, then tap 'd'". The symbol > tells the computer that what
is typed is to be put into the file dict. To view a file we use cat in a different way:
% cat dict
red rojo
green verde
blue azul
%
If we wish to add text to an existing file we do this:
% cat >>dict
white blanco
black negro
<control-D>
%
Now suppose that we have another file tmp that looks like this:
% cat tmp
cat gato
dog perro
%
Then we can join dict and tmp like this:
% cat dict tmp >dict2
We could check the number of lines in the new file like this:
% wc -l dict2
8
The command wc counts things --- the number of characters, words, and line in a file.

chmod

This command is used to change the permissions of a file or directory. For example to make a file
essay.001 readable by everyone, we do this:
% chmod a+r essay.001
To make a file, e.g., a shell script mycommand executable, we do this
% chmod +x mycommand
Now we can run mycommand as a command.
To check the permissions of a file, use ls -l . For more information on chmod, use man chmod.

cd

Use cd to change directory. Use pwd to see what directory you are in.
% cd english
% pwd
% /u/ma/jeremy/english
% ls
novel poems
% cd novel
% pwd
% /u/ma/jeremy/english/novel
% ls
ch1 ch2 ch3 journal scrapbook
% cd ..
% pwd
% /u/ma/jeremy/english
% cd poems
% cd
% /u/ma/jeremy
Jeremy began in his home directory, then went to his english subdirectory. He listed this directory using ls ,
found that it contained two entries, both of which happen to be diretories. He cd'd to the diretory novel, and
found that he had gotten only as far as chapter 3 in his writing. Then he used cd .. to jump back one level. If
had wanted to jump back one level, then go to poems he could have said cd ../poems. Finally he used cd
with no argument to jump back to his home directory.

cp

Use cp to copy files or directories.


% cp foo foo.2
This makes a copy of the file foo.
% cp ~/poems/jabber .
This copies the file jabber in the directory poems to the current directory. The symbol "." stands for the
current directory. The symbol "~" stands for the home directory.

date
Use this command to check the date and time.
% date
Fri Jan 6 08:52:42 MST 1995

echo

The echo command echoes its arguments. Here are some examples:
% echo this
this
% echo $EDITOR
/usr/local/bin/emacs
% echo $PRINTER
b129lab1
Things like PRINTER are so-called environment variables. This one stores the name of the default printer
--- the one that print jobs will go to unless you take some action to change things. The dollar sign before an
environment variable is needed to get the value in the variable. Try the following to verify this:
% echo PRINTER
PRINTER

ftp

Use ftp to connect to a remote machine, then upload or download files. See also: ncftp
Example 1: We'll connect to the machine fubar.net, then change director to mystuff, then download the file
homework11:
% ftp solitude
Connected to fubar.net.
220 fubar.net FTP server (Version wu-2.4(11) Mon Apr 18 17:26:33 MDT 1994) ready.
Name (solitude:carlson): jeremy
331 Password required for jeremy.
Password:
230 User jeremy logged in.
ftp> cd mystuff
250 CWD command successful.
ftp> get homework11
ftp> quit
Example 2: We'll connect to the machine fubar.net, then change director to mystuff, then upload the file
collected-letters:
% ftp solitude
Connected to fubar.net.
220 fubar.net FTP server (Version wu-2.4(11) Mon Apr 18 17:26:33 MDT 1994) ready.
Name (solitude:carlson): jeremy
331 Password required for jeremy.
Password:
230 User jeremy logged in.
ftp> cd mystuff
250 CWD command successful.
ftp> put collected-letters
ftp> quit
The ftp program sends files in ascii (text) format unless you specify binary mode:
ftp> binary
ftp> put foo
ftp> ascii
ftp> get bar
The file foo was transferred in binary mode, the file bar was transferred in ascii mode.
grep

Use this command to search for information in a file or files. For example, suppose that we have a file dict
whose contents are
red rojo
green verde
blue azul
white blanco
black negro
Then we can look up items in our file like this;
% grep red dict
red rojo
% grep blanco dict
white blanco
% grep brown dict
%
Notice that no output was returned by grep brown. This is because "brown" is not in our dictionary file.
Grep can also be combined with other commands. For example, if one had a file of phone numbers named
"ph", one entry per line, then the following command would give an alphabetical list of all persons whose
name contains the string "Fred".
% grep Fred ph | sort
Alpha, Fred: 333-6565
Beta, Freddie: 656-0099
Frederickson, Molly: 444-0981
Gamma, Fred-George: 111-7676
Zeta, Frederick: 431-0987
The symbol "|" is called "pipe." It pipes the output of the grep command into the input of the sort
command.
For more information on grep, consult
% man grep

head

Use this command to look at the head of a file. For example,


% head essay.001
displays the first 10 lines of the file essay.001 To see a specific number of lines, do this:
% head -20 essay.001
This displays the first 20 lines of the file.

ls

Use ls to see what files you have. Your files are kept in something called a directory.
% ls
foo letter2
foobar letter3
letter1 maple-assignment1
%
Note that you have six files. There are some useful variants of the ls command:
% ls l*
letter1 letter2 letter3
%
Note what happened: all the files whose name begins with "l" are listed. The asterisk (*) is the " wildcard"
character. It matches any string.
lpr

This is the standard Unix command for printing a file. It stands for the ancient "line printer." See
% man lpr
for information on how it works. See print for information on our local intelligent print command.

mkdir

Use this command to create a directory.


% mkdir essays
To get "into" this directory, do
% cd essays
To see what files are in essays, do this:
% ls
There shouldn't be any files there yet, since you just made it. To create files, see cat or emacs.

more

More is a command used to read text files. For example, we could do this:
% more poems
The effect of this to let you read the file "poems ". It probably will not fit in one screen, so you need to
know how to "turn pages". Here are the basic commands:

• q --- quit more


• spacebar --- read next page
• return key --- read next line
• b --- go back one page

For still more information, use the command man more.

mv

Use this command to change the name of file and directories.


% mv foo foobar
The file that was named foo is now named foobar

ncftp

Use ncftp for anonymous ftp --- that means you don't have to have a password.
% ncftp ftp.fubar.net
Connected to ftp.fubar.net
> get jokes.txt
The file jokes.txt is downloaded from the machine ftp.fubar.net.

print

This is a moderately intelligent print command.


% print foo
% print notes.ps
% print manuscript.dvi
In each case print does the right thing, regardless of whether the file is a text file (like foo ), a postcript file
(like notes.ps, or a dvi file (like manuscript.dvi. In these examples the file is printed on the default printer.
To see what this is, do
% print
and read the message displayed. To print on a specific printer, do this:
% print foo jwb321
% print notes.ps jwb321
% print manuscript.dvi jwb321
To change the default printer, do this:
% setenv PRINTER jwb321

pwd

Use this command to find out what directory you are working in.
% pwd
/u/ma/jeremy
% cd homework
% pwd
/u/ma/jeremy/homework
% ls
assign-1 assign-2 assign-3
% cd
% pwd
/u/ma/jeremy
%
Jeremy began by working in his "home" directory. Then he cd 'd into his homework subdirectory. Cd
means " change directory". He used pwd to check to make sure he was in the right place, then used ls to see
if all his homework files were there. (They were). Then he cd'd back to his home directory.

rm

Use rm to remove files from your directory.


% rm foo
remove foo? y
% rm letter*
remove letter1? y
remove letter2? y
remove letter3? n
%
The first command removed a single file. The second command was intended to remove all files beginning
with the string "letter." However, our user (Jeremy?) decided not to remove letter3.

rmdir

Use this command to remove a directory. For example, to remove a directory called "essays", do this:
% rmdir essays
A directory must be empty before it can be removed. To empty a directory, use rm.

rsh

Use this command if you want to work on a computer different from the one you are currently working on.
One reason to do this is that the remote machine might be faster. For example, the command
% rsh solitude
connects you to the machine solitude. This is one of our public workstations and is fairly fast.
See also: telnet
setenv

% echo $PRINTER
labprinter
% setenv PRINTER myprinter
% echo $PRINTER
myprinter

sort

Use this commmand to sort a file. For example, suppose we have a file dict with contents
red rojo
green verde
blue azul
white blanco
black negro
Then we can do this:
% sort dict
black negro
blue azul
green verde
red rojo
white blanco
Here the output of sort went to the screen. To store the output in file we do this:
% sort dict >dict.sorted
You can check the contents of the file dict.sorted using cat , more , or emacs .

tail

Use this command to look at the tail of a file. For example,


% head essay.001
displays the last 10 lines of the file essay.001 To see a specific number of lines, do this:
% head -20 essay.001
This displays the last 20 lines of the file.

tar

Use create compressed archives of directories and files, and also to extract directories and files from an
archive. Example:
% tar -tvzf foo.tar.gz
displays the file names in the compressed archive foo.tar.gz while
% tar -xvzf foo.tar.gz
extracts the files.

telnet

Use this command to log in to another machine from the machine you are currently working on. For
example, to log in to the machine "solitude", do this:
% telnet solitude
See also: rsh.

wc
Use this command to count the number of characters, words, and lines in a file. Suppose, for example, that
we have a file dict with contents
red rojo
green verde
blue azul
white blanco
black negro
Then we can do this
% wc dict
5 10 56 tmp
This shows that dict has 5 lines, 10 words, and 56 characters.
The word count command has several options, as illustrated below:
% wc -l dict
5 tmp
% wc -w dict
10 tmp
% wc -c dict
56 tmp

In this Document . . .

• Command words and arguments in bold typeface are shown exactly as you type them. Note that
most are in lowercase. They must be typed that way: UNIX treats uppercase letters as different
from their lowercase counterparts. For items shown in italics, substitute an appropriate value.
• Type the punctuation shown, such as a hyphen or vertical bar.
• Control characters, typed by holding down the CTRL key while typing the character, are shown by
the notation ^x, where x is the character.
• You must finish all UNIX commands by pressing the RETURN key, which is not shown here.

Connecting and Logging In

Connecting from Another Computer

If you are using another computer on the campus network (UTnet) or on the Internet, and if that computer
has a telnet command, you can use it to connect to a UNIX host. If the other computer is also running
UNIX, you can connect using rlogin. If your computer offers ssh, the Secure SHell, you can also connect
using ssh or slogin.

Connecting through Telesys

You must have a modem and a computer, and your user number must be validated to use the Telesys dial-
up system.
If you use SLIP or PPP software provided in the UT Connect package, it will make the Telesys connection,
and you can use telnet to connect to a UNIX host.
Logging In
For your first login, your login name is the user number issued to you by ACITS, in lowercase. When the
UNIX system prompts you for a password, give the password originally issued for your user number, also
in lowercase.
For your first login, a special program will prompt you for a new UNIX password, possibly for a new
UNIX login name, and for other initialization information. Then it will log you out. The login name you
choose must be unique: it cannot be used by anyone else on the system. It will also be part of your e-mail
address, so you should choose something appropriate.
Make up a password that is six or more characters long, mixing uppercase, lowercase, and numbers to
make it difficult for others to guess. This password is the only thing that keeps someone else from using
your account and having full access to your work.
The program may ask you to choose a login shell, which is a UNIX command interpreter. The C shell
(/bin/csh) is recommended. For this document, the C shell is assumed to be the command interpreter-unless
otherwise stated. The program will also prompt you for optional data to put into a database that other users
on the Internet can view. This includes such items as your name, office address, and phone number. Press
RETURN to leave any item blank.
To add or change data in a later session, use the command:

chfn

Exceptions: For the UTS system, you must run chfn on the machine named curly.cc.utexas.edu. For the
ADS and CCWF systems, send your request to

http://www.utexas.edu/cc/help/remark/

The Shell's Prompt for Commands

After you log in, you will see a prompt from the shell. The C shell's prompt usually includes the host
machine's name. When you see the shell prompt, such as ccwf.cc.utexas.edu%, you can issue UNIX
commands.

Logging Out

IMPORTANT: Don't just turn off the terminal or workstation or disconnect the phone, and do not abandon
a terminal or workstation that seems "locked up". When you are through with your UNIX session, log out
by typing:

logout or ^d

If you see a new UNIX login prompt, press ^d again. If you see a new Telesys> prompt, type:

exit

If you can't get a response at all and are unable to log out, see "Killing a Detached or Runaway Job" in this
document.

Changing Your Password

To change your password, type the command:

passwd

You will be prompted for your old password, then for your new one (twice for confirmation). If the two
new passwords match, the change will take effect in about one hour. If they do not match or are otherwise
unacceptable, you will be prompted to try again. Neither the old nor new password will display on the
screen. Changing your password on UTS, which must be done on the machine named curly.cc.utexas.edu,
does not affect your password for Telesys, CCWF, ADS, UMBS, or any other system.

Correcting Typing Errors


To correct an error before you press the RETURN key:

• Press either the DELETE or BACKSPACE key to back up over a character, depending on the
system.
• Press ^w to back up over a word.
• Type ^u to erase the entire line.

Special Characters

^c
Interrupts and aborts execution of the current process, which cannot be restarted.
^z
Suspends a process (temporarily stops it by putting it in the "background") so that you can give other UNIX
commands. To resume the process, use fg (foreground) or %n, where n is the background job number. To
disable ^z (make it undefined), give the command:

stty susp u

<
Reads from the file named to the right of this symbol instead of from standard input. Thus:

Mail jsmith < note

mails the contents of file "note" to user jsmith instead of prompting for text from your terminal ("standard
input").
>
Writes to the file named to the right of this symbol instead of to standard output. Thus:

cat myfile

displays contents of "myfile" at your terminal (standard output), but:

cat myfile > listout

copies it to file "listout" instead, overwriting and destroying any previous contents of the file "listout". (In
the C shell, a prior set noclobber command prevents such destruction.)
>>
Appends output to the file named to the right of this symbol. Thus:

cat nextfile >> listout

appends a copy of "nextfile" to file "listout" instead of overwriting what is already in "listout".
|
Creates a "pipe" so that output from one program (on left) becomes input to the next one (on right). Thus:

ls | lpr -Pcom_lw

sends output from the ls (listing) program to the lpr (printing) program.
*
Matches zero or more characters in a filename. For example, A* matches A, AbC, ARGUE, African, etc.
?
Matches any single character in a filename. For example, A?C matches AAC, ABC, ACC, etc.
\
Prevents the following character from being interpreted as special. For example, \* makes * an ordinary
character.
The shell performs filename matching and input/output redirection before calling any program that uses the
files.

Setting Your Terminal Type

Some programs must know what type of terminal you are using in order to process control characters
correctly. To identify your terminal to the C shell, give the command:

setenv TERM type

where type is the terminal type, such as vt100. Your terminal type should already be defined by
initialization files set up for you when you first used a particular ACITS UNIX system.

Getting Online Help

Online UNIX documentation consists of "man" (manual), pages that you can display or print by using the
man program. For example, to display the man page for the rm (remove) program, type:

man rm

For information on the man program itself, type:

man man

The program pauses after displaying each screenful of text. Press the space bar to continue, or press q to
quit.
To print a man page, "pipe" the output of the man program to the ul program (for underline and boldface
removal, which some printers can't do) then pipe that output to the lpr program--like this:

man rm | ul-Tdumb | lpr -Pacwl_lw

This prints the rm man page on the laser printer at the Student Microcomputer Facility. If you don't know
which man page you need, type:

apropos keyword

to get a list of man pages that contain keyword in their title lines.
On the ADS system, get additional online help by using the InfoExplorer program. Type info -h to get
started.
Longer documents and frequently asked questions can be searched and displayed by using your Web
browser to connect to:

http://www.utexas.edu/cc/unix/

Files and Directories

A UNIX filename or directory name can contain up to 255 letters, digits, and punctuation characters (best
limited to period and underscore). To list names of files in your own directory, type:
ls

This will not list filenames that begin with a period, unless you include the -a (all) option, like this:

ls -a

Names of initialization files typically begin with a period. For example, the C shell executes commands in
.login each time you log in, and those in .cshrc each time you start up the C shell. The initialization file for
the Bourne shell or the Korn shell is .profile.
Other ls options include:
-l
long form, gives file protections, size in bytes.
-F
marks directory names with a slash, executable files with an asterisk.
To list a subset of your files, use special characters. For example, to list all filenames beginning with A,
use:

ls A*

For complete information about the ls command, see:


man ls

Creating and Editing Files

To create and alter files on a UNIX system, use a text editor. The most common one is the vi editor. Its use
is described in Introduction to UNIX, CCUG-1. The pico editor is very easy to use, with an on-screen menu
of commands and built-in help.
Emacs is another popular editor. A summary of Emacs commands is in GNU Emacs Pocket Reference
List, CCRL-34, available free at the Help Desk.
NOTE: To use most editors, your terminal type will need to be defined. A definition of vt100 works in
most cases.

Displaying a File at Your Terminal

Use the cat (catenate) or more command to display files at your terminal. For example:

cat source1 source2

displays "source1" and "source2" in that order.

more testfile

displays "testfile", pausing after each screenful. Press the space bar to see each new screen.

Printing a File

To send files to a printer, use lpr. For example:

lpr -Pfacsmf_lw source1 source2

prints files "source1" and "source2" on a laser printer at the Student Microcomputer Facility (SMF) in the
Flawn Academic Center (FAC). For information about options, output devices, and locations, see:
man lpr and http://www.utexas.edu/cc/unix/print-service/

On ADS, use InfoExplorer. To learn how, type

info -h

Deleting a File

Use rm (remove) to delete files from your directory. For example:

rm trashfile

The -i (interactive) option to rm causes the system to request confirmation of each file deletion. This option
may prevent accidental deletions and is useful if you are removing several files, as in:

rm -i *file

To delete a file that starts with a hyphen, use

rm - file

Setting a Search Path

Your command search path is the sequence of directories the shell searches to find commands you issue.
For the C shell, to add a directory to the search path, use set path. For example:
set path=($path /usr/lang) ; rehash
adds /usr/lang to your current search path, $path. But this works only for the current login session. If you
want your path set as above for EVERY login session, put the set path command in your .login file.

Killing a Detached or Runaway Job

If your terminal gets disconnected from your job or if it "locks up", you can kill the detached processes this
way:

1. Log in again to the same machine (if need be, from another terminal) and type: tty (tells which
terminal line you are now using) ps -u username(username is your own username. This lists all
your running processes)
2. For lines that have "csh" in the COMMAND column and that have a terminal line in the TT
column different from your current terminal, look in the PID column for the process id number of
that C shell.
3. Send that C shell's process id (pid) a hangup signal:

kill -HUP pid

4. Repeat the ps -u username command to make sure all unwanted processes are gone. If not, reissue
the kill command like this:

kill -9 pid

Running Programs

To compile a Fortran program using the UNIX FORTRAN-77 compiler, f77, type:
f77 file

where file is the name of the source file. On ADS, you can also use xlf or xlf90. If the source filename ends
in .f it is taken to be a FORTRAN-77 program.
To compile a Pascal program, type:

pc file

where file is the name of the Pascal source file, which normally has .p as its final two characters.
Exception: on ADS systems, use

xlp file

To compile a C program, type:

cc file

where file is the name of the C source file, normally having .c as its last two characters. On ADS systems,
you can also use xlc.
To compile a C++ program with the GNU C++ compiler, type

g++ file

All of these compilers compile and load object code into executable files named a.out. To execute your
program, simply type:

a.out

If you get the message "a.out: Command not found", check to be sure that your command search path is set
correctly. Or you may be able to solve the problem by using the command:

./a.out

to specify your current working directory. To write object code to some file other than a.out, use the -o
compiler option, like this:

cc -o output

where output is the name of your executable file. To compile only, use the -c option. In this case, the
compiled program is written to a file with the same name as the source file but with the final .f, .p, or .c
replaced by .o; no loading or linking takes place.
NOTE: Programs compiled on one machine architecture will not run on another. For example, an a.out file
compiled on the CCWF system will not execute on UTS. To debug your C, Pascal, FORTRAN, and
assembly language programs, compile them with the -g option, then use an interactive debugging program.
For information on available debugging programs, type:

apropos debug

For other compiler options, see the man pages for f77, PC, and cc. On UNIX systems running AIX, see the
man pages for xlf, xlc, and xlp.
To print a listing of your program, type:
lpr -Psite -p sourcefile

To include line numbers, use:

cat -n sourcefile | lpr -Psite -p

Summary of Useful Commands

The following commands are grouped alphabetically by function. Unless noted otherwise, each has a man
page describing it in full. Commands marked "C shell only" are described in the csh man page (except on
ADS systems, where you should use InfoExplorer for information).
Access Control

exit - terminate a shell (see "man sh" or "man csh")


logout - sign off; end session (C shell and bash shell only; no man page)
passwd - change login password
rlogin - log in remotely to another UNIX system
slogin - secure version of rlogin

Communications

from - list senders of mail


Mail - send and receive mail
mesg - permit or deny terminal messages and talk requests
pine - send and receive mail (easiest for new users)
talk - talk to another logged-in user (full screen)
write - write to another logged-in user

Programming Tools

ar - archive and library maintainer


as - assembler, specific to each machine architecture
awk - pattern scanning and processing language
CC - C++ compiler (cxx on UTS; xlC on ADS)
cc - C compiler (xlc on ADS)
crontab - maintain periodic tasks
csh - C shell command interpreter
dbx - source-level debugging program
f77 - FORTRAN compiler (xlf on ADS)
g++ - GNU C++ compiler
gcc - GNU C compiler gdb - GNU Project debugger
gprof - display profile of called routines
kill - kill a process
ld - the UNIX loader
lex - generate lexical analysis programs
lint - check C source code
make - manage multipart program projects
maple - symbolic mathematics program
nice - run a command at low priority (see "man nice" or "man csh")
nohup - run a command immune to hangups
PC - Pascal compiler (xlp on ADS)
perl - Popular script interpreter
prof - display profile data
ranlib - convert archives to random libraries
sh - Bourne shell command interpreter
/bin/time - time a command
yacc - generate input parsing programs

Documentation

apropos - locate commands by keyword lookup


/usr/bin/X11/dxbook - start the BookReader program (UTS only)
info - start the InfoExplorer program (ADS only)
man - find manual information about commands
whatis - describe what a command is
whereis - locate source, binary, or man page for a program

Editors

emacs - screen-oriented text editor


ex - line-oriented text editor
pico - simple, screen-oriented text editor (easiest for new users)
sed - stream-oriented text editor
vi - full-screen text editor
vim - full-screen text editor ("vi-improved")

File and Directory Management

cd - change working directory


chmod - change the protection of a file or directory
chquota - change disk quota on ACITS UNIX systems
cmp - compare two files
comm - select/reject lines common to two sorted files
compress - compress a file
cp - copy files
crypt - encrypt/decrypt files (not on ADS)
diff - compare the contents of two ASCII files
file - determine file type
grep - search a file for a pattern
ln - make a link to a file
ls - list the contents of a directory
mkdir - create a directory
mv - move or rename files and directories
pwd - show the full pathname of your working directory
quota - display disk usage and limits
rm - delete (remove) files
rmdir - delete (remove) directories
sort - sort or merge files
tee - copy input to standard output and other files
tr - translate characters
umask - change default file protections
uncompress - restore compressed file
uniq - report (or delete) repeated lines in a file
wc - count lines, words, and characters in a file

File Display and Printing


cat - show the contents of a file; catenate files
fold - fold long lines to fit output device head - show first few lines of a file
lpq - examine the printer spooling queue
lpr - print a file
lprm - remove jobs from the printer spooling queue
more - display a file, one screen at a time
page - like "more", but prints screens top to bottom
pr - paginate a file for printing
tail - show the last part of a file
zcat - display a compressed file

File Transfer

ftp - transfer files between network hosts


rcp - transfer files between networked UNIX hosts
scp - secure version of rcp
rz - receive files using ZMODEM protocol
sz - send files using ZMODEM protocol

Miscellaneous

alias - define synonym commands


chsh - change default login shell
clear - clear terminal screen
echo - echo arguments
learn - request computer-aided instruction (not on CCWF)
pbm - portable bitmap manipulation programs
popd - pop the directory stack (C shell only)
pushd - push directory on stack (C shell only)
script - make typescript of terminal session
setenv - set an environment variable (C shell only)
stty - set terminal options

News/Networks

lynx - text-only Web browser for display terminals


netscape - Web browser
netstat - show network status (on UTS, /usr/sbin/netstat)
Pnews - submit USENET news articles
rlogin - login remotely on another UNIX system
slogin - secure version of rlogin
tin - read/post USENET news articles
trn - read/post USENET news articles
rsh - run shell or command on another UNIX system
ssh - secure-shell version of rsh
telnet - run Telnet to log in to remote host

Process Control
(The following commands function under the C shell, bash, and ksh. They do not have separate man
pages.)

bg - put suspended process into background


fg - bring process into foreground
jobs - list processes
^y - suspend process at next input request
^z - suspend current process

Status Information

spend - lists year-to-date ACITS UNIX charges


date - show date and time
df - summarize free disk space
du - summarize disk space used
env - display current environment or run programs under modified environment
finger - look up user information
history - list previously issued commands (C shell, bash, and ksh only)
last - indicate last login of users
lpq - examine spool queue
manpath - show search path for man pages
printenv - display environment
Ps - show process status
pwd - display full pathname of working directory
set - set shell variables (C shell, bash, and ksh only)
stty - set terminal options
uptime - show system load, how long system has been up
w - show who is on system, what command each job is executing
who - show who is logged onto the system
whois - Internet user name directory service

Text Processing

checknr - check nroff/troff files


col - filter reverse line feeds
dvips - convert TeX DVI files into PostScript
eqn - typeset mathematics with troff
ispell - check spelling interactively
macref - make cross-reference listing of nroff/troff macro files
neqn - format mathematics with nroff
nroff - format text for simple display
pic - make simple pictures for troff input
psdit - filter troff output for Postscript printer
spell - find spelling errors
tbl - format tables for nroff/troff
troff - format

Potrebbero piacerti anche