Useful Unix Commands - from Good Site Bad Site

Useful Unix Commands

Welcome to another goodsitebadsite blog! If there is one thing that we seem to do alot in our job, it is the constant questioning of ourselves on those simply unix/linux commands that we use regularly. Below are the commands that we use the most, which we hope will be of us to everyone!

Moving Files:

to move a file from on place or another (also can be used to rename a file) use:

mv orginal_name_and_path new_name_and_path

For example:

mv setup.php setup2.php



Copying Files:

Copying files uses the same syntax as moving a file above but uses the cp command:

cp file_to_copy destination_of_new_file

for example:

cp setup.php /var/www/vhosts/example.com/httpdocs/setup.php

The above example is presuming that you are in the actual directory where setup.php exists

Removing a file

Always be careful when on the server and removing a file!

rm filename

for example

rm setup.php

listing files

To list the files of the directory that you are in, you can use the ls command. The ls command has quite a few useful options:

ls

ls on its own will give you a simple list of files

ls -l

This can be really handy if you want to have more information show, such as file size

Changing directories

To find your way around you use the cd command

cd directory you wish

for example

cd /var/www/vhosts/example.com/httpdocs

or if you want to go back a level (presuming we are in /var/www/vhosts/example.com/httpdocs use:

cd ..

this would then take you to /var/www/vhosts/example.com

Finding where you are

If you have got yourself lost and not sure what directory you are in, use pwd

pwd

This will return your current path

Finding files

if you have mislaid a file, or need to a file, you can use the locate command

locate file_name

for example

locate setup.php