My Favorite Terminal Commands
May 24th, 2007While many of us use the terminal on a daily basis, there are a number of commands that can really make terminal life fun. Here are a few of my favorite, including some lesser-known terminal commands.
- man
Before I start, it is imperative to mention the man command. Short for manual, man formats and displays the online manual pages for most terminal commands. For example, to display the manual page for the man command, just type:man man
This will display the manual page for the man command. Now, lets get started!
- du -h -d1 and df
du is the terminal command to display disk usage statistics. There are many flags for the du command, -h outputs the directory size in human-readable format, and -d1 specifies how many directories deep to go. In this case, it will list directories one level deep. df, on the other hand, will list all volumes connected to your computer and display the amount of space used and available on each volume. Try it! - last and who
last displays the last logins of users to the machine. This is helpful in a multi-user environment if you are trying to find out who has logged into a machine. The most recent login will be listed at the top of the list. who displays the users currently logged in to a machine. - uptime
uptime displays how long your computer has been up since your last reboot. I have found this useful to check when a user complains about their system feeling sluggish. If it has been a long time, it might be time for a reboot. More than anything, uptime gives you bragging rights as to the stability of your system. - top and kill
top displays the currently running processes on your Mac. This is helpful in determining if an application or process is slowing down your system by taking up all the processing time. If you happen to find a process that you wish to quit, use the kill command:kill ###
where ### is the process ID (PID) of the process listed on the left side of the terminal window.
- open
open will tell the Finder to open a folder or file. For example:open ~/Documents/
will tell Finder to open the Documents folder of the current user, which is specified with the ~.
- dscl
dscl is the directory services command line utility. Most often, I use it to determine if a workstation is bound to an LDAP directory. Specifically, I use this command:dscl localhost -list LDAPv3
which lists the address(es) of the LDAP server(s) the workstation is bound to. Its helpful when troubleshooting Open Directory/login issues.
- locate and find
locate is a case-sensitive file search utility. Locate is much faster than find because it uses a special database, locatedb, which is updated weekly by Mac OS X. To use locate simply type:locate filename
and it will return a list of filenames that match your request. However, this is only accurate if the locate database has been updated recently. To manually update the locate database execute this command:
/usr/libexec/locate.updatedb
For a real-time, yet slower search, you can use the find command. The syntax is slightly different:
find -name filename
- periodic daily weekly monthly
periodic runs the Mac OS X cleanup/optimization scripts that normally run on a daily, weekly or monthly basis, respectively. For users who leave their Mac on 24/7, it is unlikely that running these scripts will do much good. However, if you don’t usually leave your Mac turned on, you may want to give this command a try:sudo periodic daily weekly monthly
Placing sudo in front of the command will tell Mac OS X to run the command as a superuser.
While these are only a few of the terminal commands I use on a daily basis, they might come in handy some time.