Top 10 Useful Terminal Commands

This post is going to be a first for me. I collaborated with a good friend of mine, an IT specialist who has worked in school districts as a Apple/Network guru for over 10 years, to compile some of the most useful terminal commands for an Apple user. The terminal allows users to modify and perform tasks to their system that they can't normally do. These tips are nice for the novice user to get their feet wet in using the terminal. While I've done some of this in the past I've always had help with an experienced user and would never mess around in the terminal unassisted.

Disclaimer - It is never wise to use the terminal without knowing what you are doing first. Be sure to have assistance or a reliable backup before performing such tasks. We are only trying to inform people of some of the things that can be done and help users understand what is going on under the hood.

Top 10 Useful Terminal Commands
by Al McCoy - Apple/Networking Specialist

  1. man - Man is a command which stands for manual. Not sure what command you need? You can try man -k and hope that you picked an appropriate keyword, if not, try another keyword until you find what you're looking for. Or give up and ask somebody smarter.
  2. sudo - Allows your account to run commands as superuser (root), assuming you have admin privileges or have been added to the sudoers file by an account that does have admin privileges.
  3. du -cks /* | sort -nr - Show how the files in utilize your disk. du -cks totals the sizes of all files and subdirectories inside the directory (e.g., /Applications, or ~/Desktop) in kilobytes, then sorts them from largest to smallest. Useful for finding what is filling up your disk. Use sudo if some of the files don't belong to you.
  4. ls -al - Lists all files in the current directory assuming you have adequate permissions. Shows if each item listed is a directory, with permission, owner and group info for each file as well as info on the size, age and of course the file's name.
  5. pwd - Will print on the screen what directory the OS has you currently in, no matter how you got there.
  6. cd - Change directory. Useful tricks to know with cd - cd .. will move you to the parent directory, assuming there is one. cd ~ will take you to your home directory. cd / will take you to the root of the drive, everything on the drive is contained within /.
  7. su - Allows you to switch to another account, assuming you know that account's password. This includes the superuser (root) account. Unlike sudo, which only runs the a command as root, su will switch you into root or some other account until you exit, giving you all the powers and restrictions of that account. Useful if you aren't in an admin account but know the name and password of an admin account, you can su to the admin account and then do admin stuff, including using sudo to do superuser stuff.
  8. whoami - So you're a whiz with su, you've been changing into other accounts all day, and suddenly you realize that you're not sure how many times you've exited, or to put it more succinctly, you're not sure what account you're in. whoami will list the current account, useful when things that you think should work aren't working because you're not who you thought you were!
  9. ping - This how you check that your computer can connect to another computer over the network. ping www.google.com should let you know if you can connect to google, or if you know another computer's IP address, you can do something like ping 192.168.1.1 (this is a common home router address, but may not be yours, so that one may not work for you).
  10. less - Less breaks up the results of some other command into screen size pages. This is done by piping the output of the other command to less (e.g.. ls -R | less) by placing the vertical bar or pipe character between the commands. Assuming that there is more than a single screen of output from the other command, less will show a : on the last line of the screen and pressing the space bar will advance to the next page. Some other useful keys at the : are return to advance a single line and q to exit less immediately. If less isn't available on your system, try more. As the old saying goes, less is more, more or less.

Here is another great list of Top 50 Terminal Commands from Mac Trips and Tips.

David Kapuler is an educational consultant with more than 10 years of experience working in the K-12 environment. For more information about his work, contact him at dkapuler@gmail.com and read his blog at cyber-kap.blogspot.com.