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.
Listing or showing files
List files in current directory:
Hey where is my .htaccess file?
List ALL files:
List files with additional info (permissions, etc)
List all files with additional info
Changing or navigating directories
cd [directoryname] (where [directoryname] is the folder, e.g. cd www
Go back a directory:
Go back two directorys:
Navigate to the base directory:
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:
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
The web folder might be different depending on which version of linux you are running but a common one would be
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).
Remove all gif files from current folder
Delete an empty folder
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
Move myfile.html to newfile.html
mv myfile.html newfile.html
Move a directory and contents
mv images/* media/images
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/
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.