Basic Unix Commands |
date | to display the current date and time | |
---|---|---|
kill | to kill (or destroy) the process with a given pid (process identification number) as argument | |
logout | to log out from the Unix system | |
man | to get information on a Unix command;
to look up the page in the online manual for that command | |
man CC | shows the pages of the Unix manual referring to the C++ compiler (CC) on the screen. | |
nslookup | to find the address of a given machine | |
nslookup yourmach | returns the name and address of the machine yourmach, along with the name and address of its server. | |
passwd | to change your current password | |
printenv | to show the current environment setting | |
ps | to list your current processes by their pid (process identification number) | |
setenv | to change an environment setting | |
setenv DISPLAY yourmach:0 | tells the Xserver that the Xterminal named yourmach is where any windows created are to be displayed. | |
setenv PRINTER xxx | makes xxx be the default printer for any lpr or enscript commands. | |
source | to reexecute a source shell script file | |
source .login | re-executes your .login file
(normally executed when you log in); useful after making changes to the .login file (removing the need to exit and re-login); | |
time | to time the execution of a given command | |
time anyunixcommand | executes anyunixcommand and returns the user, system, and total time taken for the execution | |
who | to list the users currently logged in
to given machine;
to find out who is logged in | |
whoami | to display login of user currently logged
onto given terminal;
to answer the question: "Who am I?" | |
cd | to change directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
cd ABC | moves to a subdirectory named ABC located below your current directory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cd .. | moves to the parent directory of your current directory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cd | moves to your home directory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cd ../ADIR | moves to a directory named ADIR located in the parent directory of your current directory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cp | to copy one file to another;
copies the contents of the first file (or directory) to the second file (or directory), without changing the contents of the first file (or directory) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cp ABC DEF | copies file ABC to (or on top of) a file named DEF. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cp -i ABC ADIR/DEF | copies file ABC to (or on top of) a file named DEF in the directory ADIR. Requests approval for overwriting the file if the file ADIR/DEF already exists. (-i means interactive.) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cp -r ADIR BDIR | copies the entire contents of the directory ADIR to a new (or on top of the old) directory BDIR. (-r means recursive.) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
expand | to expand the tab characters found
in one file
into spaces in a new file
| expand AFILE BFILE
| copies the contents of AFILE into
a new file called BFILE,
changing all tab characters to spaces.
| | ls
| to display file information
(to list subdirectory);
| lists only the file names of the files in the current subdirectory
| ls
| lists all files in your current directory.
|
| ls -a
| lists all files in your current directory, including
any dot(.) files (e.g., .login).
|
| ls *.java
| lists all files in your current directory that
end with the characters '.java' (e.g.,
example1.java).
|
| ls -F
| lists files in your current directory,
putting a slash (/) after those that are directories
and an asterisk (*) after those that are executables.
|
| ls -l
| lists all files in your current directory, showing
protection codes, date of creation (or most recent
modification), and size.
| | mkdir
| to make a new subdirectory
within (or below) the current directory
|
| mkdir BDIR
| creates a new subdirectory named BDIR
within the current working directory.
| | mv
| to rename (or move) a file;
| renames the first file (or directory) named to the name of the second; the first file (or directory) no longer exists
| mv -i ABC DEF
| renames ABC to DEF; can also
be thought of as moving the file ABC on top of file
DEF. asking permission if the file DEF
already exists. (-i for interactive.)
| | pwd
| to display full pathname of current
working subdirectory;
| to provide the name of the subdirectory you are currently working in | rm
| to remove (delete) a file;
| once deleted, this file is unretrievable (unlike the Trash Bin facility on PCs and Macs)
| rm ABC DEF
| deletes both ABC and DEF.
|
| rm -i ABC DEF
| first asks you if you really want to delete these
files; then deletes the ones for which you respond
yes (y).
(-i for interactive.)
| | rmdir
| to remove (delete) a
subdirectory;
| the subdirectory cannot contain any files; you need to rm (delete or purge) them first
| rmdir MNO
| deletes the empty subdirectory named MNO.
| |
These commands help you to compile and execute programs and applets in Java using the Java Development Kit (JDK).
javac | to compile a Java program | |
---|---|---|
javac -g acprog.java | compiles with debugger information (-g) the Java program named acprog.java into the Unicode (bytecode) file named acprog.class. | |
java | to interpret and execute a compiled Java program | |
javac aprog | interprets and runs the Java bytecode file named aprog.class. Notice that the '.class' extension is assumed by the javac command. | |
jdb | to debug a Java program | |
dbx aprog | runs the Java bytecode file named aprog.class that was compiled with a -g option in a debugging environment. Again the '.class' extension is assumed by the jdb command. | |
appletviewer | to run a Java applet | |
appletviewer anapplet.html | executes an applet that is called from an URL (or HTML file) named anapplet.html. | |
These commands help you to compile and debug programs in other programming languages.
cc | to compile a C program | |
---|---|---|
cc -O acprog.c -o acprog -lm | compiles with optimization (-O) the C program named acprog.c into the executable file named acprog, allowing the compilation to access the math library (-lm). | |
CC | to compile a C++ program | |
CC -O acprog.C -o acprog -lm | compiles with optimization (-O) the C++ program named acprog.C into the executable file named acprog, allowing the compilation to access the math library (-lm). | |
dbx | to debug a program | |
dbx aprog | runs the executable program named aprog that was compiled with a -g option in a debugging environment. | |
lint | to check the syntax of a C program | |
f77 | to compile a Fortran program | |
f77 -c fprog.f ftn1.f ftn2.f | compiles, without generating an executable file (-c), the Fortran program named fprog.f with the additional Fortran modules, ftn1.f and ftn2.f. | |
f77 -g -o debug anfprog.f | compiles the Fortran program called anfprog.f with a symbol table (-g) so that the executable file named debug can be used with the dbx command. | |
These commands allow you to see the contents of a file.
cat | to display a text file or to concatenate files | |
---|---|---|
cat file1 | displays contents of file1 on the screen (or window) without any screen breaks. | |
cat file1 file2 | displays contents of file1 followed by file2 on the screen (or window) without any screen breaks. | |
cat file1 file2 > file3 | creates file3 containing file1 followed by file2. | |
diff | to show the differences between two files | |
diff ABC DEF | displays any lines in ABC or DEF that differ from each other. | |
enscript | to print a file with filename, date, and page number | |
enscript -Pxxx -2rG ABC | prints out the contents of file ABC on the printer named xxx with two columns per page (-2), rotated 90 degrees (-r) so that it appears in a landscape format, with a gaudy heading (-G) as a shaded bar across the top that provides the filename (ABC), the creation date of that file, and the page number. | |
lpr | to print a file | |
lpr -Pxxx ABC DEF | prints out the contents of the file ABC followed by the contents of the file DEF on printer xxx. | |
more | to display a file, screen by screen;
to list the contents of a file to the terminal screen (or window) | |
more ABC DEF | displays the two files ABC and DEF sequentially on the screen. Hitting the space bar moves down one screen; the return key moves down one line. | |
pr | to paginate a file before printing it (to pretty it) | |
pr ABC DEF | breaks the contents of the files ABC and DEF into pages, puts a heading on the top of each file with the name of the file, the date and time, and a page number. The two files are numbered independently. The result goes to the screen. | |
pr ABC | lpr -Pxxx | paginates the file ABC and sends the resultant file to be printed on xxx. This is an example of a Unix command that uses a pipe) (`|'); that is, the standard output of the first part of the command (before the pipe `|') is piped to (is treated as the standard input for) the second part. | |
spell | to perform a spelling check on a file;
to list words found in the file that are not in the Unix spelling dictionary; Note: often lists words that are hyphenated (split across two lines) | |