Unix Commands
There are essentially 2 tutorials here. This page is the Unix how-to. It will teach how to learn more about commands.
The terminal tutorial goes over Mac OS X's Terminal application. It teaches a lot about using Terminal and the shell and its primary goal is to familiarize you with everything you need to do to use Terminal instead of the GUI to do everything you typically do with the Mac OS X Finder.
If you are interested in learning Unix scripting, see this great BASH shell tutorial.
I'll just plug a few other sites on similar subjects.
Finding out what commands are available
So you know that you can look in /Applications to see what programs you can run. But where do you look to find out what shell commands you can run? Try typing the following keys.
cntr-x cntr-d
You should see a long list of commands that the terminal knows about. The Terminal builds a list of commands based on what it finds in various places. By default, these are the command locations.
/bin
/sbin/
/usr/bin
/usr/sbin
There are other locations that commands are hiding in. The Terminal will NOT know about them by default. To run them, you either need to instruct Terminal to look in the folder that contains the command, or you need to run the command by typing the path to the command (absolute or relative paths will work). More about that later. But first, I'll mention where other commands are often installed. Most standard 3rd party Unix type apps will install themselves in the following locations.
/usr/local/bin
/usr/local/sbin
Then there are some other locations that contain executables by default or could have them placed there by various installers.
/usr/libexec
/usr/X11R6/bin
~/bin/
And even more more locations if you install MacPorts or Fink:
/opt/local/bin
/sw/bin
Typing the path of a command
You can run commands the Terminal doesn't know about by typing the path of the command. Here are some examples.
/usr/local/bin/gpg
If you write a script or compile a C or Java or anything that is executable, you would run it like this.
/Users/yourname/some_command
That is assuming that the command was saved to /Users/yourname. And that example is using the absolute path. You can also use the relative path like this.
./some_command
This assumes your Terminal working directory is located in /Users/yourname. If instead, you were located in /Users/yourname/Desktop, you could run the command like this.
~/some_command
../some_command
Another scenario is if your working directory is /Users/yourname, but the command is located in the Desktop folder. Then run it like this.
./Desktop/some_command
~/Desktop/some_command
You can also run GUI applications this way.
/Applications/iTunes.app/Contents/MacOS/iTunes
Almost all GUI applications have the executable command located in their Contents/MacOS/ directory and they all can be run from the command line. And there are some benefits to running them this way also. Sometimes they will print out debugging information. Another reason is that some of them take command line arguments, but they are intended only for people who know how to do it, like you if you are reading this!
/bin
Alright, lets look at some commands. This is the contents of the /bin directory as of 10.4.8.
[ df launchctl pwd tcsh
bash domainname link rcp test
cat echo ln rm unlink
chmod ed ls rmdir wait4path
cp expr mkdir sh zsh
csh hostname mv sleep zsh-4.2.3
date kill pax stty
dd ksh ps sync
I believe all of these are binary (written in c, compiled into code so that they run quickly). The source code is available for probably all of these commands on These are all "core" OS commands. You should know what everything in here does, especially cat, chmod, cp, date, echo, kill, ls, mkdir, mv, ps, rm, and rmdir. See, nearly everything. You may not need to use all of them, but you should know about them. All of these have man pages (discussed below) except for [. You should be happy to know that you can view the source code to these commands.
/sbin
Here is the contents of /sbin as of 10.4.8.
SystemStarter kerberosautoconfig mount_msdos quotacheck
autodiskmount kextload mount_nfs rdump
clri kextunload mount_ntfs reboot
disklabel launchd mount_smbfs restore
dmesg launchd_debugd mount_synthfs route
dump md5 mount_udf routed
dumpfs mknod mount_volfs rrestore
dynamic_pager mount mount_webdav rtsol
fibreconfig mount_afp newfs service
fsck mount_autofs newfs_hfs shutdown
fsck_hfs mount_cd9660 newfs_msdos slattach
fsck_msdos mount_cddafs nfsd tunefs
halt mount_devfs nfsiod umount
ifconfig mount_fdesc nologin
ip6fw mount_ftp ping
ipfw mount_hfs ping6
These are all binary, except nologin and service, which are shell scripts. Shell scripts are just Terminal commands that are compiled into a file and run. So basically, when you learn how to use the Terminal, you are learning how to write shell scripts. These are all still core OS commands but they fall under a slightly different category than /bin. These are commands that are more likely to be executed by the system, run as daemons (a service like a web server-and they often end with "d", like nfsd) or used to modify something about the system such as startup items (SystemStarter), networking (ifconfig), Kernel extensions (kextload and kextunload), firewall (ipfw), mounted file systems (mount*), etc. The commands I use most often out of this list include ping and reboot. When doing system level stuff, you may use tools like fsck, ipfw, mount and umount. You would NEVER run launchd as that is run by the system.
/usr/bin
Now we are getting to the real meat. This is the contents of the /usr/bin directory as of 10.4.8 with Apple's Developer Tools installed (you would have much less without Apple's Developer Tools).
a2p hdxml2manxml prove
acid head psed
aclocal headerdoc2html pstopdf
aclocal-1.6 heap pstruct
addftinfo hexdump ptar
afmtodit host purge
alias hostinfo pwpolicy
amber hpftodit pydoc
amlint hsdbd python
ant htdigest python2.3
appleping htpasswd pythonw
appletviewer hwprefs pythonw2.3
apply i686-apple-darwin8-g++-4.0.1 quota
apropos i686-apple-darwin8-gcc-4.0.1 ranlib
apt iconv rcs
ar id rcs-checkin
arch ident rcs2log
as idlj rcsclean
asa ifnames rcsdiff
at indent rcsmerge
at_cho_prn indxbib rdoc
atlookup info read
atos infocmp readlink
atprint infokey redo_prebinding
atq infotocap refer
atrm install reggie_se
atstatus install-info renice
autoconf install_name_tool reset
autoheader instmodsh rev
autom4te iodbc-config ri
automake iodbctest rlog
automake-1.6 iodbctestw rlogin
automator ipcrm rmic
autoreconf ipcs rmid
autoscan ipf-mod.pl rmiregistry
autoupdate irb rpcclient
auval isc-config.sh rpcgen
awk jar rs
b2m jarsigner rsh
banner java rsync
basename java-rmi.cgi ruby
bashbug javac ruptime
batch javaconfig rview
bbdiff javadoc rvim
bbedit javah rwho
bc javap s2p
bg javatool sample
biff javaws sar
bison jconsole say
bridget jdb sc_usage
bsdmake jikes scp
bspatch jinfo screen
bspatch_apple jmap script
bunzip2 jobs scrollpv
bzcat join sdiff
bzcmp jot sdp
bzdiff jps security
bzegrep jsadebugd sed
bzfgrep jstack segedit
bzgrep jstat serialver
bzip2 jstatd servertool
bzip2recover kdestroy setregion
bzless kdump sftp
bzmore keytool shar
c++ killall shark
c++-3.3 kinit shlock
c++-4.0 klist showmount
c++filt kpasswd simg4
c2ph krb5-config simg4_plus
c89 kswitch simg5
c99 ktrace sips
c_rehash kvno size
cal lam sliceprint
calendar last slogin
cancel lastcomm smbcacls
cap_mkdb latency smbclient
captoinfo ld smbcontrol
cc ld64 smbcquotas
cd ldapadd smbget
certtool ldapcompare smbpasswd
checkgid ldapdelete smbspool
checknr ldapmodify smbstatus
chflags ldapmodrdn smbtar
chfn ldappasswd smbtree
chgrp ldapsearch smbutil
chpass ldapwhoami snmpbulkget
chsh leaks snmpbulkwalk
chudRemoteCtrl leave snmpcheck
ci less snmpconf
cksum lessecho snmpdelta
clear lesskey snmpdf
cmp lex snmpget
cmpdylib lex++ snmpgetnext
co libnetcfg snmpinform
col libtool snmpnetstat
colcrt lipo snmpset
colldef lkbib snmpstatus
colrm locale snmptable
column localedef snmptest
comm locate snmptranslate
command lock snmptrap
compileHelp lockfile snmpusm
compile_et logger snmpvacm
compress login snmpwalk
config logname soelim
cpan look sort
cpio lookbib splain
cpp lorder split
cpp-3.3 lp sqlite3
cpp-4.0 lpoptions srm
crc32 lppasswd ssh
crlrefresh lpq ssh-add
crontab lpr ssh-agent
cscope lprm ssh-keygen
csplit lpstat ssh-keyscan
ctags lsbom stat
cups-calibrate lsvfs states
cups-config m4 strings
cupstestppd mDNS strip
curl machine su
curl-config mail sudo
cut mailq sum
cvs mailstat sw_vers
cvs-diff-branch mailx syslog
cvs-make-branch make tab2space
cvs-merge-branch makeinfo tabs
cvs-revert malloc_history tack
cvs-view-diffs man tail
cvsbug manpath talk
dbmmanage mate tar
dc md tbl
defaults mdcheckschema tclsh
desdp mdfind tclsh8.4
diff mdimport tcopy
diff3 mdls tdbbackup
diffpp mdutil tdbdump
diffstat merge tdbtool
dig mesg tee
dirname mib2c telnet
dirt mib2c-update testparm
disable mig testprns
distcc mkafmmap testrb
distccd mkbom texi2dvi
distccmon-text mkdep texi2html
ditto mkfifo texindex
dns-sd mklocale textutil
dprofpp mktemp tfmtodit
drutil mmroff tftp
dscl mnthome tic
dsimport monster tidy
dsperfmonitor more tiff2icns
dsymutil msgs tiffutil
du nano time
dwarfdump nasm tkmib
eaytest native2ascii tnameserv
ebrowse nbdst toe
efax nc top
efix ndisasm tops
egrep neqn touch
emacs net tput
emacs-ppc net-snmp-config tr
emacs-undumped newaliases traptoemail
emacsclient nfsstat troff
enable nibtool true
enc2xs nice tset
encode_keychange nicl tsort
enscript nidump tty
env nifind type
eqn nigrep ul
eqn2graph niload ulimit
erb nireport umask
error niutil unalias
escputil nl uname
etags nm uncompress
ex nmblookup unexpand
expand nmedit unifdef
expect nohup uniq
extcheck nroff units
false nslookup unpack200
fax nsupdate unvis
fc ntlm_auth unzip
fetchmail ntp-wait unzipsfx
fetchmailconf ntpq update_prebinding
fg ocs update_prebinding_core
fgrep ocvs update_sharing
file ocvs-diff-branch uptime
find ocvs-make-branch users
find2perl ocvs-merge-branch uudecode
findsmb ocvs-revert uuencode
finger ocvs-view-diffs uuidgen
fixproc od vers_string
flex open vgrind
flex++ opendiff vi
fmt openssl view
fold openssl_fips_fingerprint vim
formail orbd vimdiff
from osacompile vimtutor
fs_usage osalang vis
ftp osascript vm_stat
full2tt6e otool vmmap
fulldump otool64 w
funzip over wait
g++ pack200 wall
g++-3.3 pagesize wbinfo
g++-4.0 pagestuff wc
gatherheaderdoc passwd what
gcc paste whatis
gcc-3.3 patch whereis
gcc-4.0 pathchk which
gcov pbcopy who
gcov-3.3 pbpaste whoami
gcov-4.0 pcsctest whois
gdb pcsctool wish
gencat pdbedit wish8.4
genstrings pear write
getconf perl wx-config
getopt perl5.8.6 wxPerl
getopts perlbug xargs
glibtool perlcc xcodebuild
glibtoolize perldoc xcodeindex
gm4 perlivp xgrid
gnuattach pfbtops xml2-config
gnuclient php xml2man
gnudoit php-config xmlcatalog
gnumake phpize xmllint
gnuserv pic xslt-config
gnutar pic2graph xsltproc
gperf pico xsubpp
gprof piconv xxd
grap2graph pl yacc
grep pl2pm yes
grep-changelog plutil ypcat
grn pmset ypmatch
grodvi pod2html ypwhich
groff pod2latex zcat
groffer pod2man zcmp
grog pod2text zdiff
grolbp pod2usage zegrep
grolj4 podchecker zfgrep
grops podselect zforce
grotty policytool zgrep
groups post-grohtml zip
gunzip powerpc-apple-darwin8-g++-4.0.1 zipcloak
gzcat powerpc-apple-darwin8-gcc-4.0.1 zipgrep
gzexe pr zipinfo
gzip pre-grohtml zipnote
h2ph printenv zipsplit
h2xs printf zless
hash procmail zmore
hdid profiles znew
hdiutil projectInfo zprint
That is a lot of commands. A lot of these are scripts that can be easily inspected. There are sh, bash, csh, perl, python, and ruby scripts. Here is the list.
aclocal dprofpp mib2c-update read
aclocal-1.6 emacs-ppc mig ri
afmtodit enc2xs mkdep s2p
alias eqn2graph mmroff scrollpv
amlint erb neqn shar
ant fax net-snmp-config simg5
apropos fc nroff sliceprint
autoconf fetchmailconf ntp-wait smbtar
autoheader fg ocs snmpcheck
autom4te find2perl ocvs-diff-branch snmpconf
automake findsmb ocvs-make-branch splain
automake-1.6 fixproc ocvs-merge-branch testrb
autoreconf gatherheaderdoc ocvs-revert texi2dvi
autoscan gdb ocvs-view-diffs texi2html
autoupdate getopts openssl_fips_fingerprint tkmib
bashbug glibtool over traptoemail
bg glibtoolize pagesize type
bzcmp gnuattach pear ulimit
bzdiff gnudoit perlbug umask
bzegrep grap2graph perlcc unalias
bzfgrep grep-changelog perldoc vers_string
bzgrep groffer perlivp vgrind
bzless grog php-config vimtutor
bzmore gzexe phpize wait
c2ph h2ph pic2graph whatis
c_rehash h2xs piconv which
cd hash pl2pm wish
command headerdoc2html pod2html wish8.4
compile_et ifnames pod2latex wx-config
cpan instmodsh pod2man xml2-config
cpp iodbc-config pod2text xslt-config
crc32 ipf-mod.pl pod2usage xsubpp
cups-config irb podchecker zcmp
curl-config isc-config.sh podselect zdiff
cvs-diff-branch java-rmi.cgi prove zegrep
cvs-make-branch jobs psed zfgrep
cvs-merge-branch krb5-config pstruct zforce
cvs-revert libnetcfg ptar zgrep
cvs-view-diffs localedef pydoc zipgrep
cvsbug lorder rcs-checkin zless
dbmmanage mailstat rcs2log zmore
diffpp mib2c rdoc znew
I'll put off describing which commands are useful and how to find out more about these commands until later.
/usr/sbin
And the last folder we will look at. This is the contents of the /usr/sbin directory as of 10.4.8 with Apple's Developer Tools installed.
AppleFileServer httpd ntpd sendmail
BootCacheControl installer ntpdate setkey
DirectoryService ioalloccount ntpdc slapadd
KernelEventAgent ioclasscount ntptrace slapcat
ab ioreg nvram slapdn
ac iostat ocspd slapindex
accept ip6 pcscd slappasswd
accton ip6config pdisk slaptest
apachectl ipconfig periodic slp_reg
appletalk kadmin pmap_dump slpd
apxs kadmin.local pmap_set smbd
arp kadmind portmap snmpd
asr kdb5_util postalias snmptrapd
autobind kextcache postcat softwareupdate
automount kextstat postconf spray
bless kgmon postdrop sshd
blued kprop postfix stdethers
bootparamd kpropd postkick stdhosts
bpwhoami krb524d postlock swat
cac_anchors krb5kdc postlog sysctl
cac_cron ktutil postmap syslogd
chat languagesetup postqueue system_profiler
chown logresolve postsuper systemkeychain
chroot lookupd pppd tcpdchk
configd lpadmin pwd_mkdb tcpdmatch
coreaudiod lpc quot tcpdump
createhomedir lpinfo quotaoff tim
cron lpmove quotaon timed
cupsaddsmb lsof racoon timedc
cupsd lwresd rarpd timutil
dev_mkdb mDNSResponder reject traceroute
diskarbitrationd makedbm repquota traceroute6
disktool megaraid revnetgroup trpt
diskutil memberd rmt update
distnoted mkextunpack rndc vipw
dnsextd mkfile rndc-confgen visudo
dnssec-keygen mkslapdconf rotatelogs vpnd
dnssec-makekeyset mountd rpc.lockd vsdbutil
dnssec-signkey mtree rpc.statd winbindd
dnssec-signzone named rpcinfo xgridctl
dsconfigad named-checkconf rtadvd xinetd
dsconfigldap named-checkzone rtsold ypbind
dseditgroup natd rwhod ypinit.sh
dsenableroot ndp sa yppoll
edquota netinfod sc_auth yppush
fdisk netstat screencapture ypset
fsaclctl nibindd screenreaderd ypxfr
gcc_select nidomain scselect zdump
gpt nmbd scutil zic
hdik notifyd securityd
Most of these are binary, but there are a few shell and perl scripts. Once again, these are more "systemy" and "daemon" (server) types of commands. In fact, you have the AppleFileServer (which is actually a link, but still), cupsd (the printing system), httpd (Apache web server), netinfod (responsible for users and groups), smbd (Samba file server), sshd (SSH server, aka System Preferences' "Remote Login"), syslogd (what manages /var/log/system.log, the main log file), etc.,.
Builtin commands
Each shell has a list of builtin commands that are not located anywhere. To get that list for tcsh, just type builtins. To get the list for sh, you need to run the man command (I'll discuss it more below, but here this is just so you can get a list of commands).
man -k builtin
Here is the list for sh.
builtin endsw log suspend
alias esac login switch
alloc eval logout telltc
bg exec ls-F test
bind exit nice then
bindkey export nohup time
break false notify trap
breaksw fc onintr true
builtins fg popd type
case filetest printenv ulimit
cd fi pushd umask
chdir for pwd unalias
command foreach read uncomplete
complete getopts readonly unhash
continue glob rehash unlimit
default goto repeat unset
dirs hash sched unsetenv
do hashstat set until
done history setenv wait
echo hup settc where
echotc if setty which
elif jobid setvar while
else jobs shift
end kill source
endif limit stop
And the list for tcsh
: @ alias alloc bg bindkey break
breaksw builtins case cd chdir complete continue
default dirs echo echotc else end endif
endsw eval exec exit fg filetest foreach
glob goto hashstat history hup if jobs
kill limit log login logout ls-F nice
nohup notify onintr popd printenv pushd rehash
repeat sched set setenv settc setty shift
source stop suspend switch telltc time umask
unalias uncomplete unhash unlimit unset unsetenv wait
where which while
To find out what these commands do, you will need to use the man command and search the man page for "shell builtin commmands" (sh) or "builtin commmands" (tcsh). To search a man page, type "/" then the text to search for. Press the "n" key to find the next one. You will have to search a bit to find the commands...
Finding out what a command does with man
The easiest way to find out what a command does is to read its man (or manual) page. Do that by typing:
man <command>
The man pages have a strict guideline for displaying commands. Here is the man page for the command cat.
[Computer:~] james% man cat
CAT(1) BSD General Commands Manual CAT(1)
NAME
cat -- concatenate and print files
SYNOPSIS
cat [-benstuv] [-] [file ...]
DESCRIPTION
The cat utility reads files sequentially, writing them to the standard
output. The file operands are processed in command line order. A single
dash represents the standard input.
The options are as follows:
-b Implies the -n option but doesn't number blank lines.
-e Implies the -v option, and displays a dollar sign (`$') at the
end of each line as well.
-n Number the output lines, starting at 1.
-s Squeeze multiple adjacent empty lines, causing the output to be
single spaced.
-t Implies the -v option, and displays tab characters as `^I' as
well.
-u The -u option guarantees that the output is unbuffered.
-v Displays non-printing characters so they are visible. Control
characters print as `^X' for control-X; the delete character
(octal 0177) prints as `^?' Non-ascii characters (with the high
bit set) are printed as `M-' (for meta) followed by the character
for the low 7 bits.
...
The very first line tells you a lot.
CAT(1) BSD General Commands Manual CAT(1)
Compare that with this:
STRCPY(3) BSD Library Functions Manual STRCPY(3)
The number after the command name is very significant. It states what category the command belongs to. Here is a list of numbers and what they mean.
1 General commands (tools and utilities)
2 System calls and error numbers
3 C libraries
3o OpenSSL
3pm Perl modules
3x Curses
4 Devices and device drivers
5 File formats
6 Games
7 Miscellaneous information pages
8 System maintenance and operation commands
9 System kernel interfaces
You would be interested in 1, 8, maybe 4, 5, 7, but you wouldn't be interested in 2, 3, 6, 9 unless you can program c. The SYNOPSIS part of the man file tells you how to execute the command. Anything in brackets "[ ]" is optional. In the case of cat, everything is optional.
SYNOPSIS
cat [-benstuv] [-] [file ...]
That is because cat has an interactive mode, just like grep.
SYNOPSIS
grep [options] PATTERN [FILE...]
grep [options] [-e PATTERN | -f FILE] [FILE...]
SYNOPSIS
grep [options] PATTERN [FILE...]
grep [options] [-e PATTERN | -f FILE] [FILE...]
Interactive mode just means that when you type the command, the command then waits for you to do something else. So it will sit there and mystify many newbie Unix users who keep saying, "Why isn't it doing anything?" Every option you specify will change the behavior of the command, sometimes making it do something you had no idea it could do (which is why it is useful to reread man pages every time you use the command until you start to memorize the options). ... means that whatever precedes it can be repeated. In the case of grep and cat, they both have "FILE...". That means you can type more than one file, up to no limit. If something appears out of the "[ ]", it is required.
SYNOPSIS
diskutil verb [options]
...
VERBS
Each verb is listed with its description and individual arguments.
list [device]
List the partitions of a disk or all disks. If no device is
listed, than all partitions on all disks will be displayed.
info | information device
Get information on a disk or volume.
unmount [force] device
Unmount a single volume. Force will force unmount the vol-
ume.
unmountDisk [force] device
Unmount an entire disk (all volumes). Force will force
unmount the volumes.
eject device
Eject a disk.
...
The diskutil command requires a "verb", and options are depend on the verb you choose. If you look at the verbs, you can see some are optional (list [device]) and some are required (eject device). Some have optional options and required options (unmount [force] device), and one has a pipe "|". The Pipe means OR. That means the options info OR information can be used. So diskutil info device is valid and so is diskutil information device. In this case, info and information do the same thing, but most of the time or'ed options will not do the same thing, but will mean "you can do A or you can do B, but you can't do both A and B". Dash options (aka flags) can be in a stream or not in a stream, like `-Ax" vs "-A -x". Most of the time these two mean the same. But some commands may expect them in a certain format.
SYNOPSIS
lcksum [-%AiIqV] [ -D path ] [ -n [ -a ]] [ -P prefix ] -c checksum
transcript
SYNOPSIS
For instance, lcksum -csha1 file does NOT mean fsdiff -c -s -h -a -1 file. But it means lcksum -c sha1 file. lcksum -ncsha1 file does mean lcksum -n -c sha1 file. But lcksum -cnsha1 file is wrong and so is lcksum -c -n sha1 file. The -c flag requires a parameter, and putting -n after -c messes up the parse order. So lcksum -cnsha1 file does not mean lcksum -c sha1 -n file. If a flag requires some parameter (-c), then it can not have another option (-n) between the flag and the parameter. When you are using man, there are a few keys that allow you to navigate. To go to the next page, press the space bar. To go back a page, press the "b" key. To search for some text, type "/" then type the text to search for. Press the "n" key to find the next one. Here is a list of all man pages. http://developer.apple.com/documentation/Darwin/Reference/ManPages/ It also describes the sections in more detail. To search a man page, type "/" then the text to search for. Press the "n" key to find the next one. You will have to search a bit to find the commands.
Other ways to find out what a command does
What if you think you know the command name but you aren't sure it is correct? Use the whatis command.
whatis <command>
Some commands do not have man pages. If a command requires arguments, you can just type the command alone without any arguments and it will tell you how to use it.
<command>
Or you can try one of these options.
<command> -h
<command> -help
<command> --help
Sometimes a command is totally obscure, with no man page, and no usage printout. What do you do next? Google. There are TONS and TONS of websites that discuss Unix commands. But some very obscure commands, especially if they are new to Mac OS X have no web presence at all. What next? Try the following.
strings <command>
Or open the command in a text editor like BBEdit (or cat it) and look around (but don't change anything.).
Finding out what command to use
So you know what you want to do, but you don't know what command to use. Do a keyword search.
man -k <keyword>
apropos <keyword>
(apropos is the same as man -k). This will print a list of commands with man pages that contain that keyword. General words will print out a huge list. The list will include the man page category number, so you should quickly scroll and ignore the irrelevant sections (usually section 3). Of course, not all commands have man pages. So be sure to google it. And if you are really serious, you can get on lists.apple.com and search their mail lists. There are other Mac OS X Unix mail lists too, so google around. Be aware, there are always many ways to do one thing. Just pick one you think is best if you have a choice. And don't be afraid to do it badly. Everyone has to go through a period of not knowing what they are doing. If you are afraid to go there, then you wont ever be able to reach the other end of geek enlightenment.
Finding out where commands are located
locate <command>
The locate command searches an index of your hard disk. The index is updated weekly. You can update it manually by typing the following.
sudo -s
/usr/libexec/locate.updatedb &
Another way you can find is with find.
find /path/to/search -name "<command>" -print
The find command will actually look through the directories you tell it to, rather than search an index like locate does. You can also use whereis or where is (tcsh) commands.
whereis command
where is command
These two commands do basically the same thing. These commands search the command locations defined in your PATH variable, by default it includes: /bin, /sbin, /usr/bin, and /usr/bin. If the command is in one of those directories, whereis will tell you. Finanlly, the which command will tell you which command will actually be used, if more than one is returned by the whereis command.
which command
Some commands are built in to the shell environment. For example, here is which exit in sh.
which exit
no exit in /usr/local/mysql/bin /usr/local/mysql/bin /usr/local/mysql/bin /usr/local/mysql/bin /bin /sbin /usr/bin /usr/sbin
And here it is in tcsh.
which exit
exit: shell built-in command.
There is no /bin/exit or /sbin/exit or on and on. It is a command that the shell defines for you.
What commands should you know about?
I'm going to let you read the man pages to figure out the rest of the commands. I will at least give you a list of commands you will want to learn first. This isn't a comprehensive list, but it is enough that it is a good start. So here it is. Obviously, you should know the commands that let you do Finder sort of tasks.
cd rm ls mkdir rmdir pwd ditto cp mv chmod chown chgrp
And commands that let you do file viewing and editing sorts of things.
touch cat more less diff grep head tail sort uniq zcat tar wc
Then there are the text editors. If you do much system stuff, you will eventually have to use one of the latter 2 editors, so you should be familiar with what they are and how they work.
pico vi emacs
And there are general commands that are are just good to know about.
date clear man exit write du echo
And then there are commands that let you talk to other computers. The pine and lynx commands aren't part of OS X, but you should know about them since just about every other Unix server has them.
sftp ssh ping hosts hostname pine lynx curl tcpdump telnet
And there are system administration types of commands.
sudo su passwd users groups id who last
And there are debugging commands.
ps top kill fsck fs_usage sc_usage kctrace kdump ifconfig lsof netstat
And then there are Mac OS X commands that are very useful.
diskutil disktool system_profiler osascript nvram killall lookupd dscl scutil sips screencapture
Most of these commands have many methods of operation. Depending on the context that you launch it, and the parameters you give them, the commands will do different things. Happy man page reading!
Finding out how to get more commands
Many commands can be downloaded off the internet and installed just like any application, via an installer. The command osxutil is pretty cool. Get osxutil here: osxutils.sourceforge.net/ As is wget. Get wget here: macosx.forked.net/showcat.php?cat=Networking&sortmethod=name. Note, macosx.forked.net is just Fink (see below) repackaged, and it isn't updated nearly as much as Fink is, so... Or you can download the source code for many utilities and compile them if you have the developer tools installed. Of course, you ALWAYS read the README before you install anything with the developer tools. Sometimes you will to actually edit some configuration files to make the app work on Mac OS X. It is usually very hard the first time, but the more you do it, the easier it gets. And you should never NEVER compile and install something that is from an untrusted source. The way to compile and install an app is almost always as follows.
cd ../path_to_the_source_code
./configure
make
sudo make install
If the command doesn't require root permissions to be installed, you won't need sudo for the last command, but most of the time you will. See: www.tldp.org/LDP/LG/current/smith.html What if you don't want to bother with the configure, make, and make install stuff? Many apps have been compiled already and are just waiting to be downloaded via MacPorts or Fink. They are kinda hard to setup for the first time, but if you really decide you want to work only in the terminal, these are very good things to get. I wont attempt to explain how to set those up. www.macports.org/ fink.sourceforge.net
Directory Commands
| Command Name | Usage | What the command does |
| Change Directory | cd dirname | Changes the directory to the specified directory |
| cd | Changes to your home directory | |
| cd .. | Changes back one directory | |
| List | ls | Lists directory contents |
| ls -l | Lists directory contents and some info | |
| ls -al | Lists all directory contents even "hidden" files | |
| ls -l | more | Lists directory contents one screen at a time | |
| Make Dirctory | mkdir dirname | Makes a directory with the specified name |
| Remove directory | rmdir dirname | Removes specified directory |
| Current working directory | pwd | Tells you what directory you are in |
File commands
| Command Name | Usage | What the command does |
| Copy | cp file newfilename | Copies the file |
| cp file dirname | Copies the file into the specified directory | |
| cp * dirname | Copies all the files into the specified directory | |
| cp -r * / dirname | Copies all the files in this directory and it's subdirectories into the specified directory | |
| Move | mv filename newdirectory | Moves the file into specified directory |
| mv oldfilename newfilename | Changes the filename | |
| Remove | rm filename | Deletes the file forever |
| Change mode | chmod go+rx filename | Allows other internet surfers to view and run the file |
| chmod go-rx filename | Disallows other internet surfers to view and run the file | |
| Catolog | cat filename | Displays the file |
| cat file1 file2 > newfile | Combines the two files | |
| More | more filename | Displays the file one screen at a time |
| Difference | diff file1 file2 | Show differences in two files |
| Pico | pico filename | Edits or creates the file |
Other commands
| Command Name | Usage | What the command does |
| Cancel | ctrl-c | Cancels the last command |
| Change Password | passwd | A program runs and you can change your password |
| Clear screen | clear | the screen clears |
| Manual | man commandname | Displays confusing information about the unix commands |
| Exit | exit | a.k.a. Logoff |
| ctrl-d | logoff | |
| Lynx | lynx | WWW browser w/o graphics |
| Date | date | Displays the current day and time |
| Disk Usage | du -k | Displays how much memory your files take up in kilobytes |
| Write | write account (such as jer29950) | If the person is logged on, everything you type after that will be sent to their account. It is like a one way telegram. |
| ctrl-d | ctrl-d ends the message. | |
| Message | mesg -y | Allows others to write you |
| mesg -n | Disallows others to write you | |
| mesg | Tells you whether write is y or n |