You are on page 1of 3

What are the most commonly used commands?

Here are some short notes on the most commonly used commands. (I
explain the origin of the command name in those cases where it isn't
Note that there are more details about several of these commands in some
of the other sections of this FAQ.
For full details about any of these commands, read the corresponding 'man'
page - for example to find out more about the 'ls' command, read 'man ls'.
(By the way, the man pages are split up into sections. You will mostly be interested in section 1
since that describes the commands you can run from the shell. Sections 2 & 3 describe C-
functions that are useful when you are writing a program.)

And if you are looking for a command to do something that isn't mentioned
here, note that 'man -k some_subject' will show a list of man pages where
"some_subject" is mentioned. That might help you find a command to do
what you want. Another method of finding useful commands is to look at
the "See also" section of related commands.

The 'whatis' command will give you a quick summary of what a given
command is for.
You could get a list of all commands in your execution PATH, with a
summary of what each command does, by running the following rather
complicated command:
echo $PATH | sed -e 's/:/ /g' | xargs -J % find % -maxdepth 1 \
( -type f -or -type l \) | xargs basename | sort | uniq | xargs
whatis 2> /dev/null | grep -E '\((1|1m|6|8)\)' | perl -ne
'($name, $descrip) = m/^(.*?)\s+- (.*)$/; $name =~ s/\((1|1m|6|
8)\)//g; printf("%-20s - %s\n", $name, $descrip)'
It might be useful to save that list in a file for future reference. (See the
question "How can I redirect the output from a command into a file?")

File and folder management

cd ("change directory") - to navigate to a different location in the
pwd ("print working directory") - show the current location in the
filesystem (the "current directory")
ls ("list") - to show details about files and folders
touch - to create an empty file or to change the date on an existing file
mkdir ("make directory") - to create a new folder
chown ("change owner") - to change the owner of a file or folder
chmod ("change mode") - to change the permissions of a file or folder
mv ("move") - to move a file or folder to a different location in the
filesystem, or just to rename it
cp ("copy") - to copy a file or folder
ln ("link") - to make a link to a file or folder
rm ("remove") - to delete a file
rmdir ("remove directory") - to remove a folder
find - to search the filesystem for files or folders matching given criteria
locate - to see where certain files are located (uses a database that is
updated periodically)
du ("disk usage") - to show the amount of disk space used by a file or
tar ("tape archive") - to bundle up a bunch of files/folders into one file
zip, gzip - to bundle up a bunch of files/folders into one file and compress it
to take less disk space
unzip, gunzip - to uncompress a .zip or .gz file

File content
more - to display the contents of a file page by page (press Return to go
down one line, press space to go down one page)
cat ("concatenate") - to display the full contents of a file or to concatenate
two or more files into one
head - to display the first part of a file
tail - to display the last part of a file
diff - to compare two text files (or, with the "-r" option, two folders)
cmp - to compare two binary files
pico - an editor for displaying and editing text files
grep ("global regular expression print") - to search inside a file for lines
matching a given pattern
sed ("stream editor") - to modify the text that is streaming through a pipe
sort - to sort the lines of text files
uniq - to filter out repeated lines of text files
fold - to wrap long lines of text files (useful when printing)
hexdump - to show the contents of a file as hexadecimal numbers
textutil - convert plain text to HTML or RTF (and vice versa)

ps ("process status") - to see detailed info about the processes running
top - to get a summary of the processes running and resource consumption
kill - to terminate a process identified by process-id (or to send other
killall - to terminate a process identified by program name
lsof ("list open files") - show which files (and sockets) are open by which
fs_usage ("filesystem usage") - show which programs are accessing
(reading or writing) the filesystem

ifconfig ("interface configure") - to display and configure network interface
ping - to send a test packet to another computer (amusing article about the
history of this command)
traceroute - to see the route taken by packets across a network
host - to find out the IP address corresponding to a hostname or viceversa
curl - to download contents of a document via a URL
ftp - command-line FTP client
ssh ("secure shell") - remote login to another computer

System Info
hostname - reports the name of your Mac
sw_vers - reports the OS X version that you are using
system_profiler - reports on the hardware and software that is on your Mac
(i.e. a command-line version of the "System Profiler" utility)
sysctl -a - reports values of the kernel parameters

echo - to send something to "standard output" (useful in pipes, etc)
open - to open a file (in the GUI application that is associated with that file
type) or a folder (in the Finder)
date - to display the current date and time (in various formats)
sleep - to pause execution for a given number of seconds (useful in scripts)
wc ("word count") - to display the number of characters, words, and lines
in a text file
pbcopy ("pasteboard copy") - copy to the clipboard from "standard input"
pbpaste ("pasteboard paste") - paste from the clipboard to "standard
xargs - pass arguments to another command (useful in pipes)
id - report info about your user account (numeric user-id, group ids, etc)
sudo ("superuser do") - execute a command with 'root' privileges
man ("manual") - to display detailed information about a command.