More information on almost all of the commands that follow can be found in the online manual. At the command line, type "man command-name", where command-name is the command you wish to search, e.g., mkdir.

Basic Unix Commands

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
  • What's in this file? more, less, cat
  • What's 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
    Directories

  • Where am I now? pwd
  • Moving around: cd , ln
  • Create a directory: mkdir
  • Delete a directory: rmdir
  • Change permissions to a directory: chmod


    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
  • Printing a file: lpr
  • Check the print queue: lpq
  • Cancel print jobs: lprm
  • Transfer files over Network: ftp
  • HOW DO I QUIT? logout


    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 executablename -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 also 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 directory. Otherwise, it takes you to the directory named. "cd /" will take you to 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 permissions on this file. The next three characters, "r-x" shows that people in the same group have read and execute permission on the file. Finally, the last three characters "r-" show that everyone else only has read permission on that file ( To be able to enter a directory, you need read AND execute permission ). Users can 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 remove the read ("r" ) and execute ("x") permissions from the group ("g") and others ("o").


cmp {file1} {file2}
Compares the contents of two files from each other. Reports the first different character found, and the line number.
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 "src" subdirectory.
ctags
Creates a tags file for use with ex and vi. A tags file gives the location of functions and type definitions in a group of files. ex and vi use entries in the tags 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 compiling your source code. Allows you to set break-points, single step through the 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 GNU project ). If filename is present, it will start editing that file. Type "<CTRL>-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 environment 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@squall (55)> file *
    useful.dvi: data
    useful.hlp: English text
    useful.tex: ascii text
    xwin.dvi: data
    xwin.tex: English text
    ertle@squall (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 looking for a specific filename, then replace "t*" with "filename", and "find" will print 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 software/data/documents from them for free. After connecting, "ls" will print out the files in the current directory, and "get filename" will transfer the named file into 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 similar to those of "cc". More information available under "gcc" in the emacs information 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 from 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-points in the source file. More information available under "gdb" in the emacs information browser ( M-x info while in emacs ).
ghostview {filename.ps}
X PostScript previewer. PostScript is a text processing and graphics language, and ghostview is handy for looking at the resulting page or picture before you send it to the printer.
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 the command line, and also through emacs with M-x ispell-buffer.
jobs
Shows backgrounded (<CTRL>-z"ed) processes with pid ../?Page=compservices/unixbasic.php#"s. If you use "jobs" to find 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 many features as GNU"s emacs, but some people prefer it. <CTRL>-x <CTRL>-c to exit.
less filename
Displays file with minimal space.
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 names.
logout
Exits and disconnects your network connection.
lpq {-Pprintername}
Reports all print jobs in the queue for the named printer. If no printer is named 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 with -Pprintername, but the "PRINTER" environment variable is set, then the job will 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 from 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 of 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 permissions on this file. The next three characters, "r-x" shows that people in the same group have read and execute permission on the file. Finally, the last three characters "r-" show that everyone else only has read permission on that file ( To 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 see if you have any mail in your mail box. With a "login-name", "mail" will let you type in a message to send to that person. For more advanced mail processing, you 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 give you the manual pages for the write command, and "man 2 write" will give you the 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 username" will prepare a message to "username".
ps {options}
"ps" reports that status of some or all of the processes currently running on the 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.
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".
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 prefer, 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 you hit the carriage-return. Press <CTRL>-D to end the message. Write won't work if the other user has typed "mesg n".
xcalc
X scientific calculator.
xclock
X clock.
xgdb
X interface to the gdb debugger.
xman
X interface to the online manual pages.
yppasswd
Interactively changes your password.

Advanced Unix Commands

Files


Colors

  • editing colormaps : bitmap
  • view a color based on decimal values (on SGI"s) : cedit
     

 

|
Pipe symbol - send the output of one process into another process. For example, the "ls -l" command prints out all of the files in the current directory, along with information about those files, and the "more" command displays only one screenful of information at a time. If there are a lot of files in the current directory, you might want to try "ls -l | more", which makes "ls -l" send all of it"s output to "more" which then displays it one screenful at a time. Another useful one is "ps -ef | grep USERNAME", replacing USERNAME with the user you"re looking for: it will only show the lines with that user in them.
> filename
Redirect output to a file. This symbol will send the output of a command to the specified file. For example, "ls -l > names.dat" will put the names and permissions of all the files in the local directory into a file named "names.dat". If you don"t want to see any output from a command, you can send the output to "/dev/null" ( "ls -l > /dev/null" would send the names to "/dev/null", though it doesn"t really serve a purpose in this example ).
< filename
Redirect input from a file. This symbol will take everything in the file and send it to a process as if it came from the standard input ( usually the keyboard ). For example, the "spell" program reads from standard input and prints out the words that it thinks are misspelled. So, you can type "spell<RET>", then type in the words that you want to check followed by <CTRL>-D ( the end of file mark ), and spell will print out the misspelled words. If you wanted to check all of the words in a file, you"d redirect the standard input to come from the file "spell < filename", and spell would read the file instead of the keyboard.
&
Make a process run in the background automatically. The process must not need input from the keyboard or output to the screen. Say the process is "cat file1 file2 > file3" and the that file1 and file2 are large. This could take a while before it finishes. To make it run in the background ( which will allow you to continue to work while it is running ), the easiest thing to do would be to use the "&", like so: "cat file1 file2 > file3 &".
%#
Part of the process control available under the csh shell. "%#" ( where "#" is replaces with a job number ) will re-enter a suspended process. If you use "jobs" to find 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

Where the first number ( in brackets ) is the job number, and typing "%1" at the command line would cause you to re-enter the emacs job.

[CTRL]-c
Part of the process control available under the csh shell. <CTRL>-C sends a termination signal to current process. This usually kills the current process.
[CTRL]-z
Part of the process control available under the csh shell. <CTRL>-Z sends a terminal stop signal to the current process. This allows you to temporarily exit a running process, and re-enter it with "fg". The "jobs" command will show you what processes you have done this to. If the process doesn"t require input from the keyboard or output to stdout ( usually the screen ), then after using "<CTRL>-Z" you can make the process run in the background with "bg".
Dvi {-Pprintername}filename.dvi
Dvi prints out "filename.dvi" files, which are produced by the TeX and LaTeX text processing programs. More information on TeX and LaTeX can be found in the printed manuals, available for borrowing at the EM computer facility. "-Pprintername" tells Dvi which printer to print out on. This parameter isn"t necessary if you"ve set your "PRINTER" environment variable (do this with the "setenv" command ).
Vroff filename
Vroff is an X-windows previewer for documents that use the nroff/troff text processing commands. For more information, look in the document formatting portion of the printed manuals in room 252 - the "Nroff/Troff User"s manual" and the "Troff Tutorial" are both worth looking at.
Xroff {-Pprintername}filename
Xroff prints out documents that use the nroff /troff text processing commands. For more information, look in the document formatting portion of the printed manuals in Votey Hall, Rm. 252 - the "Nroff/Troff User"s manual" and the "Troff Tutorial" are both worth looking at. "-Pprintername" specifies which printer to send the print job to ( i.e. -Pcolorlaz ). This parameter isn"t necessary if you"ve set your "PRINTER" environment variable ( do this with the "setenv" command ).
awk
Pattern scanning and processing language. Very useful for making text filters. "awk" can run it"s own script files ( "awk -f scriptfile inputfile" would run the script file on the input file ), or it can accept quick scripts on the command line - "awk "length < 80" filename" prints to stdout ( usually the screen ) all of the lines in the file "filename" that are shorter than 80 characters.
bg
Background a stopped job. If you start a process that doesn"t require input from the keyboard or output to the screen, then you can make it run in the background. Say the process is "cat file1 file2 > file3" and the that file1 and file2 are large. This could take a while before it finishes. If you start the process, and then realize that you want to make it run in the background ( which will allow you to continue to work while it is running ), type "<CTRL>-Z" and then "bg". The process is now backgrounded. You can see the status of the job with "jobs" or "ps".
bitmap {filename}
X-windows bitmap viewer/editor. Bitmaps can be used for X-window icons and backgrounds. (best if run from SGI machine, and SUN server (tyr, freyr)
cedit
X-windows color viewer. Shows what color a particular decimal value of RGB looks like. Runs from SGI machines.
compress {filename}
Reduces the size of the named file using adaptive Lempel-Ziv coding. Whenever possible, each file is replaced by one with the extension ".Z", while keeping the same ownership modes. If "filename" isn"t specified, compress will compress its standard input.
etags
Creates a tags file for use with emacs and epoch. A tags file gives the location of functions and type definitions in a group of files. Emacs and epoch use entries in the tags file to locate and display a definition. To go to a function definition in emacs, type "M-." ( Meta period ). This will ask you the name of the function that you wish to find. Type it in and press return. If what you typed in is found at the beginning of a number of functions, you might not get the correct one on the first try. If this is the case, keep typing "M-," ( Meta comma ) until you reach the one that you want.
fg {%jobnumber}
Run a currently backgrounded process in the foreground. If you use "jobs" to find the processes that you have suspended or 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

Simply typing "fg" at the command line will put you back in the process that has the "+" in the 2nd column, in this case it would be the "badb" process. "fg %2" will put you back in the "elm" process.

grep {string}{-e expression}{filename(s)}
Along with egrep and fgrep, grep is used to search files for a string or a regular expression. If no "filename" is given, grep searches it"s standard input for the the string or expression. When grep finds the requested string or expression, it prints out the line that contains it along with the filename of the file that the line is from. Example: "grep chance *" will search all of the files in the current directory for the word "chance".
gtar
GNU project"s version of "tar". gtar"s command line parameters are similar to those of tar. gtar has the added advantage of not trying to keep the original file ownership of files being extracted. All files are changed to belong to the person doing the extraction. To create an archive, you might type "gtar cvf archname file1 file2 file3", which would put file1-3 in the archive named archname. "c" of "cvf archname" in the command line means create the named archive, "v" means verbose - print names of the files and the operation performed on them, and the "f archname" gives the name of the archive that you want to do the operations on. "gtar tvf archname" will print out the names of all of the files in the archive, "gtar xvf archname" will extract all of the files from archname, and "gtar xvf archname filename" will extract only "filename" from the archive, provided that it is in the archive in the first place.
kill -9 {PID}{%job-number}
Terminates a process with the process id of PID or the specified job number. See "jobs" and "ps" for information on how to find PID"s or job numbers. So, if the PID is 12345, then "kill -9 12345" will kill the job. If the job number is 5, then "kill -9 %5" will kill it.
latex filename.tex
LaTeX is a text processing language ( a superset of the TeX language ), and "latex" compiles this language into a device independent (dvi) representation of the resulting document. "latex" will report errors and, if there are none, give you a file named "filename.dvi". This file can be previewed with "xdvi", and may be printed out with "Dvi". More information on the LaTeX language is available in the LaTeX manual which you can borrow from a CEMS counselor.
nroff {filename}
"nroff" and "troff" are text processing languages. The "nroff" program is an ASCII previewer for nroff/troff files, showing what the file will look like when it is printed ( prints to stdout - usually the screen ). This can be handy for looking at nroff/troff files that you are writing "nroff filename | more", or for looking at the manual pages that come along with software that you get from the Internet "nroff -man filename | more". "Vroff" is a graphical previewer of nroff/troff files that will show different fonts and point sizes ( which the nroff program won"t ).
nice {command}
Runs a {command} with low priority so others dont experience "lagg-time".
popd
Removes the top directory from the directory stack, placing you into the new top directory. Use pushd to place new directories on the stack. If the stack consists of the following ( leftmost is the top of the stack ): "/usr / /usr/local/bin", then you will be in the "/usr" directory, and typing popd will make the stack look like this: "/ /usr/local/bin", putting you in the root directory ( / ).
pushd {directory}
Pushes "directory" on to the directory stack, placing you into that directory. If "directory" isn"t specified, pushd swaps the two top directories on the stack, placing you into whichever directory is now on the top of the stack. Use popd to remove stack entries. If the directory stack looks like this ( use "dirs" to print out the current directory stack, and the leftmost directory is top of stack): "/ /bin", and you type "pushd /usr/local/bin", then the new stack looks like this: "/usr/local/bin / /bin", and you will be in the /usr/local/bin directory. If you then type "pushd", the stack will look like this: "/ /usr/local/bin /bin" and you will be in the root directory. Finally if you type "pushd +2" the stack will look like this: "/bin / /usr/local/bin", and you will be in the /bin directory.
sed {-e script}{-f scriptfile}{filename}
Stream editor. Useful for making text filters. "sed" can take its instructions from a file ( -f scriptfile ) or the command line ( -e script ). For example "sed -e "s/test/testing/g" filename" will replace every instance of the word "test" with the word "testing" and print the result to stdout ( usually the screen ).
sort {options}{filename}
Sorts the input lines alphabetically by default, numerically if given the "-n" command line option. Without a "filename", sort works on the standard input. Otherwise it sorts the lines in the file and writes the sorted output to stdout ( usually the screen ).
tar
Creates tape archives, plus adds to, and extracts files from tape archives. Sometimes has permission problems when extracting files by maintaining the ownership of the files in the archive. If you have this problem, try "gtar". To create an archive, you might type "tar cvf archname file1 file2 file3", which would put file1-3 in the archive named archname. "c" of "cvf archname" in the command line means create the named archive, "v" means verbose - print names of the files and the operation performed on them, and the "f archname" gives the name of the archive that you want to do the operations on. "tar tvf archname" will print out the names of all of the files in the archive, "tar xvf archname" will extract all of the files from archname, and "tar xvf archname filename" will extract only "filename" from the archive, provided that it is in the archive in the first place.
uncompress filename.Z
Uncompresses files that have been compressed with the "compress" command (which automatically adds the ".Z" to the end of the filename).
uudecode filename
Decodes files that have been encoded with the "uuencode" command. "uuencode" changes binary files into ascii files so that they can be easily e-mailed or posted to the news.
uuencode {source-file}file-label
Converts a binary file into an ASCII-encoded representation that can be sent using mail(1) or posted to a news-group. If you don"t specify "source-file", then uuencode takes its input from standard-input. "uuencode" sends the encoded output to stdout ( usually the screen ). When decoded using "uudecode" the resulting file will be named "file-label".