15 Very Useful Fundamental Commands from the Command Line For Web Developers

What is the command line (prompt)? In simplest form, the command line is a user interface that’s navigated by typing commands, as opposed to using the mouse.

Advantages of using the command line instead of your GUI (graphical user interface):

  1. control of the file system and operating system, for example easily copy a specific file from one location to another with a one-line command.
  2. Speed, often only need to execute a few lines to perform a task.
  3. Low resources
  4. Scripting
  5. Remote access

Just to name a few.

Now I’m not saying you should be using the command line for everything, this is just a primer to give you a few suggestions of ways to speed up your development.  (If you use any commands that are not listed here please leave me a note in the comments, as this will be by no means a complete list.)

First Step:  Finding the command line on your computer?

Mac: If your on a Mac your looking for the Terminal.  Macintosh HD > Applications > Utilities > Terminal.  Now for convenience your going to want to keep this in your Dock, so just drag-and-drop it in an empty space on the Dock.

Windows: If your on a PC your looking for the command Prompt. To access the command prompt, go to the Start menu, click run, and type cmd.

Second Step:  Jumping right in! (the best way to really understand any of this is to actually try it out!)

  1. ls  this will list everything in the directory that you are currently in, this is helpful if you don’t know where you are or if what you are looking for is in this location. $> ls
  2. ls -alh -alh modifies the standard list in 3 ways. a shows all files, even hidden files, l shows a long format, things like file size and the date every file was last modified, h makes the sizes display in convenient units.
  3. cd  change directory.  By itself (or cd~) will always put you back into your home directory. $> cd .. will move you up one directory. $> cd – will move you to the last directory you where in. $> cd dir/dir/dir  will move you down through directories Example: $> cd /Applications/MAMP/htdocs/ (If you us a stack such as MAMP, you will need to navigate to the htdocs directory)
  4. pwd  Stands for print working directory. You’ll see output like this: /Users/chris
  5. to make a directory, use mkdir dirname
  6. chmod to change the permissions on a file or directory.  Example: $> chmod 775 file.php
  7. tar SSH Script to Compress Folder on server. Example: tar jcvf folder.tbz folder
  8. zip Example: file.txt or zip -r directory and unzip

SSH” refers to both the client software that allows secure communications and the command that is used to do logins to remote systems. Make sure that you have access setup through your hosting service provider.   If your on a Mac your in luck, it’s already installed and you can access it through the Terminal.  If your on a PC you will need to use a program such as Putty or OpenSSH. ( I will be going into SSH in more detail in an upcoming post, so stay tuned for that!) 

$> ssh yourusername@yourserver you will be promoted for your password

Use sftp (Secure FTP) and scp (Secure Copy) in the Terminal window to get and put.

  1. To access your server via sfpt $> sftp yourusername@yourserver then you will be promoted for your password
  2. The scp command can be used in three ways: to copy from a (remote) server to your computer, to copy from your computer to a (remote) server, and to copy from a (remote) server to another (remote) server.
  3. Example 1. From your local computer to remote: $> scp examplefile yourusername@yourserver:/home/yourusername/
  4. Example 2. From your remote to local: $> scp yourusername@yourserver:/home/yourusername/examplefile

Here are a couple thing that I will be covering in more detail in upcoming posts:

  1. Editing files & text (pico/nano/vi). Here is a quick glimps at one of them (find more about vi here)
  2. Accessing MySQL


vi – VI is a screen-based editor.  The VI editor lets a user create new files or edit existing files. The command to start the VI editor is vi, followed by the filename.  (This editor is not for everyone, but can be very useful!) Lets say you need to quickly edit your local database configurations in a config.php file.

  1. Rather then opening the file in your text editor just $> cd into the directory with the config.php file
  2. enter $> vi config.php.  To edit the file you need to be in insert mode, type  i.
  3. To exit insert hit esc
  4. SHIFT + to go into command mode
  5. :q!  This force quits the file without saving and exits vi
    :w This writes the file to disk, saves it
    :wq This saves the file to disk and exists vi
    :$  Takes you to the last line of the file
    :0  Takes you to the first line of the file
  6. and to exit vi hit zz this will save and quit at the same time.
Hopefully you’ll have something to add! Leave a comment if you do.
  1. Dave

    Another awesome post, thanks for the well explained info, bookmarked your site.