At some point during your life as a web developer, it will become necessary to execute commands via SSH. Now, SSH isn’t that complicated to get to grips with, but if you don’t use it all the time, chances are you’ll forget some of the most basic (and useful) commands, so I’ve listed the ones I tend to use most of the time here, for your reference.
This article assumes you’ve got an SSH client and know how to connect to your webserver and login.
Change Directory
When you login to your server you’ll probably need to change directory to that which holds all the public HTML files, something like /public_html or /htdocs or /httpdocs. For me, my most common is /public_html, so here’s the command to move to that directory. If yours is different, simply substitute the /public_html with the name of your directory
cd public_html
If you want to navigate to a subdirectory within /public_html, in this example it’s ‘demo’, you can then do so by executing the following command:
cd demo
Of course, if you want to navigate straight to a subdirectory within /public_html, you can do that from the start with a command such as this:
cd public_html/demo
Move up a directory
To move out of the ‘demo’ subdirectory, back to /public_html, all you need do is execute this command:
cd ..
Copy a folder to another location
In this case, I want to copy the folder ‘/public_html/images’ to another directory: ‘/public_html/demo/images’. I’ve already navigated to the /public_html folder using the above command. By entering the following into SSH, I can execute the copy of the ‘images’ folder from one directory to another:
cp -R images demo/images
If you’ve already got a directory within ‘demo’ called images that you want to replace with the contents of this one, then use the following command which will copy the whole directory across, overwriting any existing files or folders
cp -Rf images demo/images
Changing Permissions
If you can’t copy over some files, that might be fine if you didn’t want to replace them anyway, but if you do wish to replace the files in the destination folder, navigate to it and execute this command:
find . -type f -exec chmod 777 {} \;
This will find all files and change their permissions to Read, Write, Execute (777), which will then allow you to repeat the previous command. When you’re finished, execute the following to set them back to their intended permissions setting (644):
find . -type f -exec chmod 644 {} \;
A similar command can also be executed for folders as well:
find . -type d -exec chmod 777 {} \;
If you’re editing folders though, they need different permissions from files, so this would be the command to set them back to their default setting:
find . -type d -exec chmod 755 {} \;
Unpacking a file
Most good web software such as blogs, shopping carts, social software comes pre-packed in a compressed archive with the extension tar.gz (or even tgz) which makes it extremely portable and easy to unpack on your web server (assuming it’s a Unix/Linux server here). To unpack the file, execute this command:
tar -xvzf yourfile.tar.gz
There are varying commands for different types of compression: .tar files have a different command, as do .zip files, so check before executing this command that your files are tar.gz or tgz files.
Remove a Folder
If you want to delete an entire folder on your server, there is a very simple SSH command for this that’ll save you lots of time if previously the only way you could do it was via FTP. In this example I have a folder called ‘test’ in the ‘httpdocs’ directory of my server (the directory that contains all the files and folders that www’ers see when they visit your domain). What I’ll do in this sequence after logging in, is navigate to httpdocs and then remove the ‘test’ folder:
cd httpdocs
rm -Rf test
Create a Folder
To create a new folder using SSH, simply navigate to the desired location on your web server, then execute a simple command. In this example, I’m looking to create a folder in my ‘/public_html’ directory called ‘test’:
cd public_html
mkdir test


