Common Unix commands
A lot of our customers are amazed when something that takes them minutes, or hours, can be done by us in seconds. There are thousands of useful commands that you can use on our servers to get the most out of your hosting. Some of the more popular are:
Chmod is used to change permissions on files and folders. The syntax is fairly straight forward. Generally it is run as chmod XXX filename, where XXX are the permissions for the owner,owner's group, and everybody else. For a detailed guide on how permissions work, check out http://www.perlfect.com/articles/chmod.shtml
wget can be used to download files from remote http/ftp servers to your home directory, without having to download them to your home computer first. For instance, to download http://www.somewebsite.com/file.zip using wget, log in with ssh and run
Want to backup some files from your website? Log in with ssh and you can tar the files into a large file for zipping. Try
tar -cf backup.tar *.html
This will place every html file in the current directory into a single file called backup.tar, which you can then compress using zip, gzip or bzip.
One of my most-used commands, grep will search a file for a given pattern. It can search multiple files, and also traverse directories. For instance.
grep whatever *
This will search all file for the word whatever.
grep -i whatever *
This is the same, but the -i means case-insensitive. Grep will find "whatever", "Whatever" or even "WhAtEvEr".
grep -r whatever *
The -r means recursive, so not only will grep search every file in the current directory, but also every file in any subdirectories.
Locate will do just that, it locates all copies of a file on the computer. It uses a database that is rebuilt periodically, so it will not always show files added recently, nor will it show files you do not have permission to access. This can be useful for finding a file you have misplaced.
Which will, strangely enough, tell you which program it runs for a command. It takes one argument, for instance.
This will return the path to the program that is run when you type sendmail on the command line. In this case /usr/lib/sendmail.
Man is the single most useful command you will ever learn. Man will load the manual for a given program. For instance:
This will give you the manual file for sendmail. Very useful for troubleshooting problems, or learning new capabilities of a program.
ln creates a link between two files, kind of like a shortcut in windows. The are two kinds of links, symbolic & hard links. Hard links must be on the same filesystem, and for all intents and purposes are indistinguishable from the original file. You cannot hardlink folders, only files. Symbolic links are often more useful, as they can link to other filesystems, and folders. A symbolic link is much more like a shortcut in windows. Often customers want quick access to their error logs, so a symbolic link can provide this.
ln -s /var/log/httpd/error_logs/username username
This will create a new link called username that points to /var/log/httpd/error_logs/username.
ls is the unix equivalent of dir in dos. It will show you a listing of the files in the current directory. You can use switches to control the output, for instance ls -h will show the results with the file size in more readable form than bytes, usually megabytes or gigabytes.
will show a list of all files, including hidden files with their permissions and filesize as well.
Cat is short for concatenate. At its simplest, cat is used to show the contents of a file, (warning, do not run this over binary files like pictures, only over text files). You can also use commands like more or less, to page the file one screen at a time.
zcat/zgrep are two tools for working with gzip compressed files, rather than having to uncompress and then cat/grep the files, the zcat/zgrep tools can do this in one go.
This is by no means an exhaustive list of unix commands, nor is it a complete manual on how to use the ones listed. This is just a small list of their capabilities. You can read a lot more on sites like http://www.gnu.org/