DHTMLdev.com — Dedicated to quality Web development articles and tutorials
Web dev cheatsheet for Linux PDF Print E-mail
Tuesday, 09 May 2006

UPDATED. Added mv (move) command to this growing but brief list of common Linux commands used in Web development. It is mainly a place for me to document the common commands I use, instead of having to look them up. If I go a few months without needing to log into Linux, I tend to forget a few of these. Use this cheatsheet for the most common command line tasks in Unix/Linux, including commands for working with files and directories, and common vi commands.

Working with Files and Directories

Name Command Example Definition
Change Directory cd cd /home/myname The command cd moves from one directory to another directory. To move to the root (top) directory, type cd / and to move up one directory, type cd ../
Make Directory mkdir mkdir mydirectory Create a new directory.
Copy cp cp -r /home/myname /backups/myname The cp command copies files and directories. Using the -r option, cp will copy all subdirectories as well. If a directory has subdirectories you must use -r or cp will fail.
Move mv move demo rails/demo The move commend moves files and directories. You may also use this command to rename files and directories, for example, move myfile myfile2, would actually rename the file.
List ls ls -ls List directory contents. ls takes several parameters. Try this one to list files ls -ls
Print Working directory pwd pwd Prints the complete path of current directory.
Set File Permissions chmod chmod 755 myfile.cgi The most common need to chmod a file is when dealing with CGI scripts.
Delete a directory and all it's files and sub-directories rm rm -dfr <directory-name> Deleting a whole directory tree is not possible using rmdir. You must use rm.
Unzip a zip file unzip unzip <directory-name> Unzip a zip file into the current directory
Create a zip file zip zip <directory-name> Create a zip file of a directory
Copy a file zip zip <directory-name> Create a zip file of a directory
Change user ownership of a file or directory chown chown -R myusername mydirectory Set the user ownership of mydirectory and all sub-directories to myusername
Change group ownership of a file or directory chgrp chgrp mygroup myfile Set the group ownership of myfile to mygroup

Links

vi and vim text editor

This table shows commands used from within vi. To start vi, from the command line type vi. If you wish to open an existing file or create a new file, supply the filename as an argument, for example, vi /home/myusername/new.htm.

Name Command Example Note
Find / /Test Searching for text using vi is with the / operator. Example /Auth would find the next occurrence of "Auth."
Insert Mode i i Type i to enter insert mode.
Exit insert mode Press the esc key - Type esc to exit insert mode.
Write buffer to file :w Type :w to save changes by writing the buffer to the file.
Quit vi :q Type :q to quit. This will quit vi and return you to the command line in Unix/Linux.

Useful vi Links

Apache commands

Command Example Note
Starting apache Restarting apache gracefully apachectl graceful Restart apache gracefully so the Web site is not offline during restart.

Other Useful Links and Tutorials

Last Updated ( Monday, 31 December 2007 )