David Slack - Web developer
Published on David Slack - Web developer (https://www.davidslack.co.uk)

Home > Useful Linux commands

Useful Linux commands

This is some of the things I keep forgetting and things I always use. Might be usefull to someone (including me)

Find the hostname:

{syntaxhighlighter brush: as3;fontsize: 100; first-line: 1; }hostname{/syntaxhighlighter}

Change driectory:
cd

{syntaxhighlighter brush: xml;fontsize: 100; first-line: 1; }{/syntaxhighlighter}

E.g. To change to the root directory use

{syntaxhighlighter brush: as3;fontsize: 100; first-line: 1; }cd /{/syntaxhighlighter}

Rename a file:

{syntaxhighlighter brush: as3;fontsize: 100; first-line: 1; }rn FILENAME NEW_FILENAME{/syntaxhighlighter}

Find the version of the Linux OS (mine is CentOS 5.5)

{syntaxhighlighter brush: as3;fontsize: 100; first-line: 1; }cat /etc/*release*{/syntaxhighlighter}

If you are told you have an email by the system e.g. You have mail in /var/spool/mail/root then use 'cat' to read it. So for the above you could try

{syntaxhighlighter brush: as3;fontsize: 100; first-line: 1; }cat /var/spool/mail/root{/syntaxhighlighter}

Check the files/folders in a folder
ls

To create a tarball from the folder httpdocs make sure your in the right folder so use 'ls' then if you see the folder type

{syntaxhighlighter brush: as3;fontsize: 100; first-line: 1; }tar -zcf httpdocs.tar.gz httpdocs{/syntaxhighlighter}

To copy a folder and all files use cp -R <SOURCE> <DESTINATION> like:

{syntaxhighlighter brush: as3;fontsize: 100; first-line: 1; }cp -R /home/foo/public_html/ /home/bar/public_html/{/syntaxhighlighter}

To delete a folder and all the files in it use rm, so to delete the folder 'foo' from the folder we are in use

{syntaxhighlighter brush: as3;fontsize: 100; first-line: 1; }rm -rf foo{/syntaxhighlighter}

To change all the files in a folder to the same permission we use chmod recursive like chmod -R xxxx /path/to/top/directory so to get all the files in the file folder we could use

{syntaxhighlighter brush: as3;fontsize: 100; first-line: 1; }chmod -R 0777 files{/syntaxhighlighter}

To update php to the newest version of 5.2 you must exclude all 5.3 versions like:

{syntaxhighlighter brush: as3;fontsize: 100; first-line: 1; }yum update PHP --exclude=php*5.3*{/syntaxhighlighter}

Tags
server
Linux commands

David Slack - www.davidslack.co.uk - 07833 608098 -me@davidslack.co.uk