Common ssh file/folder commands for the web developer

Sometimes web developers don’t need to just build websites but we need to go and poke, tweak and otherwise tinker with the server themselves.  To a windows-based developer getting down and dirty with the Linux command line can be a little daunting.  However, there are some standard commands that you will need which may help ease you in.  Often with commands you will be able to apply additional instructions or parameters called arguments.  These may preceded with – or  –. You can often concatenate these (see ls below for an example).  There are usually a lot of arguments you can use and they are different for each command.  You can get help (a list of the things you can do) by adding -h  or -help after the command.  e.g.

ls -help

Listing or showing files

List files in current directory:

ls

Hey where is my .htaccess file?
List ALL files:

ls -a

List files with additional info (permissions, etc)

ls -l

List all files with additional info

ls -al

Changing or navigating directories

cd [directoryname]         (where [directoryname] is the folder, e.g.   cd  www

Go back a directory:

cd ../

Go back two directorys:

cd ../../

Navigate to the base directory:

cd /

There are usually two key locations that a web developer needs to know about:  where the configuration and log files are and where the web files are.   The configuration files are (usually) located inside the etc folder.  You would navigate to this by doing:

cd /etc

You are probably interested in the apache (web server) stuff so look for a folder called httpd.  Note the ‘d’ at the end historically stands for daemon – basically refers to a service or something that runs in the background.

Log files such as error logs or visitor logs are probably located in the /var/log  directory

cd /var/log

The web folder might be different depending on which version of linux you are running but a common one would be

cd /var/www/html/

This latter one means go to the root /   and then into var, then into www, then into html

Remove files and folders

be very careful with your location when using rm (remove).  Do not delete system files or folders.  There be dragons and you could have a CDM (career defining moment).

rm myUnwantedFile.html

Remove all gif files from current folder

rm *.gif

Delete an empty folder

rmdir  myFolder

Delete a folder and contents

rm -rf myUnwantedFolder

the -r means recursive and the -f will stop it asking you to confirm whether you want to delete

Moving Files

Move myfile.html to newfile.html

mv myfile.html newfile.html

Move a directory and contents

mv images/* media/images

Copying Files

Copy originalFile.html  to a new file, copiedFile.html

cp originaFile.html copiedFile.html

Copy a folder/directory and all files within

cp -R images/  images_backup/

the -R means recursively

If you want to overwrite any existing files during the copy process you will need to use the -f argument:

cp -Rf image/  images_backup/

Handy Tips

When using an ssh command line console you can cycle through previously typed commands using the up and down arrow keys.

If you have long file or folder names, to save typing them start typing the beginning and then press the tab key to auto-complete the file or folder name.  If you have similar name files pressing tab will fill the gap until you need to decide which bit you want.  Just type again and then press tab again after that.  Give it a go to see what I mean.

Facebook Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Apply your human brain cells and complete this highly complicated maths problem *