Basic Command Line Utilities, Tips, & Commands

Feb 7, 2007 - 9 Comments

Terminal in OS X Many Mac users avoid the command line altogether, a reasonable amount probably don’t even know it exists. For the curious out there, here are some basic and essential commands and functionalities to know if you want to get started using the Mac OS X Terminal. We’ll cover simple file manipulation, maneuvering in the file system, displaying and killing processes, and more. Remember to remove the brackets or the commands won’t work.

The Command Line Basics

  • ls -la list all contents of a directory including hidden files
  • cd [directory] move to the specified directory, cd /Applications will move to your applications folder
  • mv [file1] [file2] mv is able to rename files or move them, depending on usage
  • cp [file] [destination] copies a file to either a new filename or destination
  • cat [file] | more display contents of a file screen by screen by ‘piping’ the contents through more
  • touch [file] creates a file with the given name, eg: touch test.txt will create a blank text file
  • top display a continuously updated list of all running processes, including memory and cpu usage, PID is the process ID which you would use to kill a process
  • ps -aux list all processes running from all users, -ux will list only processes of current user
  • kill -9 [pid] kill the specified process id (basically force quit for the command line)
  • rm [file] rm removes the specified file or directory, there is no warning so use with caution
  • ping [ip] determine network latency by pinging another host

General Command Line Usability Tips

  • Use the tab key, the tab key will autocomplete directories and filenames for you
  • Enable colored terminal, this makes it easier to browse through large amounts of files
  • If a command confuses you, try running it with the –help flag, which will often display basic instructions on the given command
  • Remember manual pages exist on many commands as well, access them by typing man [command], eg: man ping
  • If the output of a command flies by you and is too much to fit on one screen, try piping it through more, like so: ls -la |more this will enable you to see the output a screen at a time
  • You can export the contents of a file, output of a command, and results of a script to a text file using the alligators (improper terminology, excuse my forgetfulness), eg: ls -la /Applications > applist.txt
  • If you’ve ever noticed your CPU load skyrocket inappropriately, a good place to find the errant process is with the top command, use top in conjection with kill to find the process ID and kill the CPU hog
  • Don’t be afraid to get your hands dirty!

For more info, tips, and tricks, be sure to check out our other command line entries and read Ten OS X Command Line Utilities you might not know about.

.

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS, Tips & Tricks

9 Comments

» Comments RSS Feed

  1. […] you are absolutely clueless about command line interfaces and are on a Mac using OS X then check this link to learn more. If PC is your platform and you are also in need of some command-line information then check this […]

  2. […] you are absolutely clueless about command line interfaces and are on a Mac using OS X then check this link to learn more. If PC is your platform and you are also in need of some command-line information then check this […]

  3. […] Basic Command Line Utilities, Tips, & Commands – OS X Daily (tags: unix bash tutorial) […]

  4. russell says:

    Don’t forget open, which opens a file as if it were double clicked in the Finder, or open -a names an application like open -a Mail.app
    you could use this to edit dot files that don’t show up in the finder, for instance open -a TextEdit.app .bashrc

    open -f is a lot like more, but it can be directed at a mac application: ls -la | open -f TextEdit.app

    Also pbcopy puts text on the Mac clipboard, for instance ls -la | pbcopy copies the output of the ls command.

  5. TrafReffins says:

    if you don’t want to go through the hassle of reading an entire man page, try the ‘whatis’ command, try it on another command as so: whatis ls

    this will report a simple one line explanation of the commands usage. Probably more useful for the advanced users out there…

  6. Loup-Vert says:

    How does one enable a colored terminal, exactly? And does that mean coloring the prompt and pre-prompt text, or enabling colors for files, e.g. making ls show folders as blue, executables as green, etc.?

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site