Unix/Linux Command Reference

File Commands

CommandDescription
lsdirectory listing
ls -alformatted listing with hidden files cd dir - change directory to dir
cdchange to home
pwdshow current directory
mkdir dircreate a directory dir
rm filedelete file
rm -r dirdelete directory dir
rm -f fileforce remove file
rm -rf dirforce remove directory dir *
cp file1 file2copy file1 to file2
cp -r dir1 dir2copy dir1 to dir2; create dir2 if it doesn't exist
mv file1 file2rename or move file1 to file2
if file2 is an existing directory, moves file1 into directory file2
ln -s file linkcreate symbolic link to file
touch filecreate or update file
cat > fileplaces standard input into file
more fileoutput the contents of file
head fileoutput the first 10 lines of file
tail fileoutput the last 10 lines of file
tail -f fileoutput the contents of file as it grows, starting with the last 10 lines

Process Management

CommandDescription
psdisplay your currently active processes
topdisplay all running processes
kill pidkill processs id pid
killall prockill all processes named proc *
bglists stopped or background jobs; resume a stopped job in the background
fgbrings the most recent job to foreground
fg nbrings job n to the foreground

File Permissions

CommandDescription
chmod octal filechange the permissions of file to octal, which can be found separately for user, group, and world by adding:
4 - read (r)
2 - write (w)
1 - execute (x)
 Examples:
chmod 777 - read, write, execute for all
chmod 755 - rwx for owner, rx for group and world. For more options, see man chmod.

SSH

CommandDescription
ssh user@hostconnect to host as user
ssh -p port user@hostconnect to host on port port as user
ssh-copy-id user@hostadd your key to host for user to enable a keyed or passwordless login

Searching

CommandDescription
grep pattern filessearch for pattern in files
grep -r pattern dirsearch recursively for pattern in dir
command | grep patternsearch for pattern in the output of command
locate filefind all instances of file

System Information

CommandDescription
dateshow the current date and time
calshow this month's calendar
uptimeshow current uptime
wdisplay who is online
whoamiwho you are logged in as
finger userdisplay information about user
uname -ashow kernel information
cat /proc/cpuinfocpu information
cat /proc/meminfomemory information
man commandshow the manual for command
dfshow disk usage
dushow directory space usage
freeshow memory and swap usage
whereis appshow possible locations of app
which appshow which app will be run by default

Compression

CommandDescription
tar cf file.tar filescreate a tar named file.tar containing files
tar xf file.tarextract the files from file.tar
tar czf file.tar.gz filescreate a tar with Gzip compression
tar xzf file.tar.gzextract a tar using Gzip
tar cjf file.tar.bz2create a tar with Bzip2 compression
tar xjf file.tar.bz2extract a tar using Bzip2
gzip filecompresses file and renames it to file.gz
gzip -d file.gzdecompresses file.gz back to file

Network

CommandDescription
ping hostping host and output results
whois domainget whois information for domain
dig domainget DNS information for domain
dig -x hostreverse lookup host
wget filedownload file
wget -c filecontinue a stopped download

Installation

CommandDescription
./configure
make
make install
Install from source
dpkg -i pkg.debinstall a package (Debian)
rpm -Uvh pkg.rpm install a package (RPM)

Shortcuts

CommandDescription
Ctrl+Chalts the current command
Ctrl+Zstops the current command, resume with fg in the foreground or bg in the background
Ctrl+Dlog out of current session, similar to exit
Ctrl+Werases one word in the current line
Ctrl+Uerases the whole line
Ctrl+Rtype to bring up a recent command
!!repeats the last command
exitlog out of current session

* use with extreme caution

to top

Last reviewed10/28/2008 4:38:24 PM

a place of mind, The University of British Columbia