• Support
  • Articles
  • Resources
  • Products

Basic Unix/Linux Commands

Interactive Features
TABCommand completion (not supported by certain shells)
UPARROWCommand history (not supported by certain shells)
CTRL-CInterrupt current process
CTRL-DIf a program/command waits for input, end input
Wildcards and Directories Used in Commands
*Replaces any string of characters in a file name except the initial dot
?Replaces any single character in a file name except the initial dot
~The home directory of the current user
~abcde123The home directory of the user abcde123
..The parent directory
.The present directory
/The root directory
Example:  ls ~/csc219/*.txt
Redirections and Pipes
COMMAND < FILECOMMAND will take input from FILE
COMMAND > FILEPut output of COMMAND to FILE
COMMAND >> FILEAppend the output of COMMAND to FILE
COMMAND 2> FILEPut error messages of COMMAND to FILE
COMMAND 2>> FILEAppend error messages of COMMAND to FILE
COMMAND > FILE1 2> FILE2Put output and error messages in separate files
COMMAND >& FILEPut output and error messages in the same FILE
COMMAND >>& FILEAppend output and error messages of COMMAND to FILE
COMMAND1 | COMMAND2Output of COMMAND1 becomes input for COMMAND2
COMMAND | moreSee the output of COMMAND page by page
COMMAND | sort | moreSee the output lines of COMMAND sorted and page by page
Online Help
COMMAND --help | moreBasic help on a Unix COMMAND (for most commands)
COMMAND -h | moreBasic help on a Unix COMMAND (for some commands)
whatis COMMANDOne-line information on COMMAND
man COMMANDDisplay the UNIX manual page on COMMAND
info COMMANDInfo help on COMMAND
xmanBrowser for Unix manual pages (under X-windows)
apropos KEYWORD | moreFind man pages relevant to COMMAND
help COMMANDHelp on a bash built-in COMMAND.
perldocPerl documentation
Online Help
lsList contents of current directory
ls-lList contents of current directory in a long form
ls -aSame as ls but .* files are displayed as well
ls -alCombination of ls -a and ls -l
ls DIRECTORY List contents of DIRECTORY (specified by a path)
ls SUBDIRECTORY List contents of SUBDIRECTORY
ls FILE(S)Check whether FILE exists (or what FILES exist)
pwdDisplay absolute path to present working directory
mkdir DIRECTORYCreate DIRECTORY (i.e. a folder)
cdChange to your home directory
cd ..Change to the parent directory
cd SUBDIRECTORYChange to SUBDIRECTORY
cd DIRECTORYChange to DIRECTORY (specified by a path)
cp FILE NEWFILECopy FILE to NEWFILE
cp -r DIR NEWDIRCopy DIR and all its contents to NEWDIR
mv FILE NAME Rename FILE to new NAME
mv DIR NAMERename directory DIR to new NAME
mv FILE DIRMove FILE into existing directory DIR
ln -s FILE LINK>Create symbolic LINK (i.e. shortcut) to existing FILE
quotaDisplays your disk quota
rm FILE(S)Remove FILE(S)
rmdir DIRECTORYRemove empty DIRECTORY
rmdir -r DIRECTORYRemove DIRECTORY and its entire contents
rm -rf DIRECTORY Same as rm -r but without asking for confirmations
touch FILEUpdate modification date/time of FILE
file FILEFind out the type of FILE
gzipCompress or expand files
zipCompress or expand files
compressCompress or expand files
tarArchive a directory into a file, or expand such a file
Text Files
more FILEDisplay contents of FILE, page by page
less FILEDisplay contents of FILE, page by page
cat FILE Display a file (for very short files)
head FILEDisplay first lines of FILE
tail FILEDisplay last lines of FILE
pico FILEEdit FILE using a user-friendly editor
nano FILEEdit FILE using a user-friendly editor
kwrite FILEEdit FILE using a user-friendly editor under X windows
gedit FILEEdit FILE using a user-friendly editor under X windows
emacs FILEEdit FILE using a powerful editor
vim FILEEdit FILE using a powerful editor with cryptic syntax
aspell -c FILECheck spelling in text-file FILE
cat FILE1 FILE2 > NEWAppend FILE1 and FILE2 creating new file NEW
cat FILE1 >> FILE2Append FILE1 at the end of FILE2
sort FILE > NEWFILESort lines of FILE alphabetically and put them in NEWFILE
grep STRING FILE(S)Display lines of FILE(S) which contain STRING
wc FILE(S)Count characters, words and lines in FILE(S)
diff FILE1 FILE2 | moreShow differences between two versions of a file
COMMAND | cut -b 1-9,15Remove sections from each line
COMMAND | uniqOmit repeated lines
Programming Languages
javac CLASSNAME.javaCompile a Java program
java CLASSNAME Run a Java program
javadoc CLASSNAME.java Create an html documentation file for CLASSNAME
appletviewer CLASSNAMERun an applet
pythonListener of Python programming language
cc -g -Wall -o FILE FILE.cCompile C source FILE.c into executable FILE
gcc -g -Wall -o FILE FILE.cCompile C source FILE.c into executable FILE
c++ -g -Wall -o FIL FIL.cxxCompile C++ source FIL.cxx into executable FILE
g++ -g -Wall -o FIL FIL.cxxCompile C++ source FIL.cxx into executable FILE
gdb EXECUTABLEStart debugging a C/C++ program
make FILECompile and link C/C++ files specified in makefile
Internet
lynxWeb browser (for text-based terminals)
firefoxWeb browser
konquerorWeb browser
BROWSERBrowse the Internet
BROWSER FILE.htmlDisplay a local html file
BROWSER FILE.pdfDisplay a local pdf file
muttText-based e-mail manager
pineText-based e-mail manager (on some systems)
ssh HOSTOpen interactive session on HOST using secure shell
sftp HOSTOpen sftp (secure file transfer) connection to HOST
rsync ARGUMENTSSynchronize directories on local and remote host
Process Control
A process is a run of a program. One program can be used to create many concurrent processes. A job may consist of several processes with pipes and redirections. Processes are managed by the kernel. Jobs are managed by a shell.
CTRL-ZSuspend current foreground process
fg Bring job suspended by CTRL-Z to the foreground
bg JOBRestart suspended Job in the background
psList processes
ps -efComplete list processes
jobsList current jobs (A job may involve many processes)
kill PROCESS Kill PROCESS (however some processes may resist)
ctrl-CKill the foreground process (but it may resist)
kill -9 PROCESSKill PROCESS (no process can resist)
COMMAND &Run COMMAND in the background
Environment Variables in Bash
env | sort | moreList all the environment variables with values
echo $VARIABLEList the value of VARIABLE
unset VARIABLERemove VARIABLE
exportVARIABLE=VALUECreate environment variable VARIABLE and set to VALUE
Miscellaneous
exitExit from any shell
logoutExit from the login shell and terminate session
svnVersion control system
xtermA shell window under X-windows
xcalcA calculator under X-windows
xclockA clock under X windows
xeyesThey watch you work and report to the Boss :-)
dateDisplay date and time
clearClear shell window
xrefreshRefresh X-windows