10 Basic Linux Commands No Web Developer Should Live Without

10 Basic Linux Commands No Web Developer Should Live Without

This post is the first in a series of list posts that will detail some of the methods, services, and software I have come to rely on in my 6 years of web development experience. In this list, I will share with you the 10 Linux commands that have been making my job so much easier since I began using the Linux command line for my web hosting server about 2 years ago. I can guarantee that when you start using these commands you will find it tedious and frustrating to go back to your old ways!

Resources

To use these commands you need a Linux hosting account or operating system. You will need to make sure that you have SSH (Secure Shell protocol) access. Shared hosting services such as GoDaddy sometimes make it a pain to get this type of access, but trust me, it’s worth it in the end. Some hosting control panels have built in Java applets for a SSH terminal. In my experience you are better off using a client program. For Mac users I recommend using the terminal built in to Coda. For PC I’ve used Poderosa but can’t vouch for it being the best option. Finally, you’ll want a reference handy. You can find handy pocket reference books on Amazon for cheap, but I prefer the online reference Linfo or a quick Google search for anything it doesn’t have.

10 Awesome Linux Commands

Don’t be intimidated; the following commands are very easy to use for people who are new to the command line. I have chosen these commands because their functions are so common in web development but the methods of accomplishing them without the command line are very tedious, time consuming, and sometimes poorly supported by software. You can also use the man command when at the command line to look up how to use a particular command. Keep in mind that your installation might not support all of these commands but you can install them or, better yet, you can have tech support install them.

1. cd

The cd command is used to change directories. Probably the most common command used at the command line. To use the command, type “cd” followed by the location of the directory relative to the current directory. To go up one or more directories, type “cd ../../” with a “../” for each level up you wish to go. To go sideways from the current directory you would type “cd ../siblingdir” where “siblingdir” is the name of the directory located in the same directory as the current one. A useful tip is to take advantage of the auto-complete when typing directory names. Enter some characters and hit tab and if there is a file or directory that uniquely begins with those characters, its name will be auto-completed for you. The time you save with auto-complete adds up quickly, making it a valuable shortcut.

2. ls

Another commonly used command is the ls command, used in order to view the contents of the current directory. It takes many optional parameters, allowing you to view more details such as file size, modification date, and owner. To use the command, type “lsfollowed by any number of parameters such as “–all” (shows more info, including hidden files).

3. mkdir

The mkdir command simply creates a new directory (folder). I find it is even faster than creating a folder via a software with a GUI. To use the command, type “mkdir directoryname” where “directoryname” is the name of the new directory.

4. mv

The mv command performs a task almost instantly that some GUI programs can take a very long time to accomplish, and that is move a directory or file to another location on the server. This is especially handy when moving very large files or directories containing many files or sub-directories. To move a directory type “mv subject destination” where “subject” is the file or directory you wish to move and “destination” is where you wish to move it to. This is also the command used to rename files or directories. The subject can be renamed by setting the destination to the new name.

5. cp

The cp command is used to copy the subject or subjects to another location. Type “cp subject1 subject2 subject3 destination” where any number of subjects can be listed. In many GUI programs, this function is executed on the client rather than the server, making it very time consuming for large copies.

6. rm

Another useful command is rm. It is used to remove (delete permanently) files and directories. This command can be very dangerous so be sure to triple check your syntax, especially when deleting directories recursively (all directories within a directory). To delete files, type “rm file1 file2 file3″ where any number of files are allowed. By default the command doesn’t remove directories because this could be dangerous. In order to do so, you need to provide the “-rf” parameters like so: “rm -rf dir”.

7. tar

The tar command is invaluable for backup as well as when you need to FTP a large amount of files. The command creates an uncompressed archive of files and directories. For day to day web development, you’ll save a lot of time by “tarring” files before you download them to your client by FTP because instead of downloading dozens, hundreds, or even thousands of individual files and directories, you download them all as one file with one constant FTP connection. To make a tar archive, type “tar -cvf archive.tar directory1″ or “tar -cvf archive.tar file1 file2 file3″ where “archive.tar” is the name of the archive you are creating and directory1 is the name of the directory to archive or with any number of files. Archives can be unarchived by changing the “-c” (create) parameter to “-x” (extract). If you see the value in this command, I suggest reading the manual for all the advanced features it can provide.

8. zip / unzip

The zip and unzip commands are very similar to the tar command. The main difference is that the archive file created is compressed. It’s so similar that I will leave it up to you to visit the manual page to learn to use it.

9. wget

One of my favorite commands is wget which allows you to download a remote file (from anywhere on the web) directly to the server at blazing speeds (depending on your host). This is particularly useful when, for example, you need to install a WordPress plugin and all you have is the URL to the .zip file. Just find the full URL to the file and type “wget http://downloads.wordpress.org/plugin/polldaddy.1.8.5.zip” and the file will be downloaded directly to the current directory on the server, bypassing your client machine and the time consuming downloads and uploads associated with the FTP process. There are advanced options available if the file is protected by HTTP authenticated login.

10. svn

This command is my all time favorite and will be covered in my next Web 2.0 Journal entry on Subversion For Web Developers.

4 comments for this entry:

  • Andrew Dahl

    *sigh* I think you should have included some more useful commands instead of the first six. Although, maybe sitting at a terminal all the time makes me forget that other people don’t use the terminal, I don’t know.

    I would’ve included: awk/grep/sed/vi/view/tail and a few others, I’m sure.

    Also, I’d have to say I enjoy hg more than svn ^_^ just sayin’.. just sayin’…

    • Fenix

      This post was an assignment for a web class of mine where the students have barely used the command line. I wrote about the commands I use every time I do web work. I’ll be honest I’ve only heard of a couple of the commands you mentioned. I’m sure my experience with Linux is barely touching the surface but this was an attempt to get people to realize there is nothing to be intimidated about and that there are many easy to use commands for Linux to help out in ordinary web developer tasks.

    • Andrew Dahl

      I just noticed I never replied to this…

      And yeah, I get annoyed with people when they see the command line and freak out… thinking that a GUI is the only way. At work, my boss jokingly said that we were all going to have to start using Linux, at which point someone said “Heh.. might as well switch to DOS”.

      Much hate for the world. In any case, kudos to you for making an attempt to open people’s eyes.

Leave a Reply

Note: Use @reply syntax to notify previous commenters of your reply. User names are case sensitive.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Friendly Sites

I recommend these links...