Basic Command Line Utilities, Tips, & Commands

Posted on February 20, 2008. Filed under: Hosting, Leopard, OSX, Servers, Software | Tags: , , , , , , , |

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 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 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!

Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

One Response to “Basic Command Line Utilities, Tips, & Commands”

RSS Feed for Mac OSX Hosting! Comments RSS Feed

For all things Unix on Mac OS X you should also see Hyperjeff’s OS X page and resources such as codesnippets by joyent. Just my 2 cents!

Where's The Comment Form?

  • Blog Stats

    • 160,100 hits
  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 21 other followers

Liked it here?
Why not try sites on the blogroll...

%d bloggers like this: