Quick Linux guide for myself in case I forget.  Here are Linux command line codes to do various things on a server hosting environment or home linux install.  Many of these linux commands will work on Mac too.

Breaking News - click here!

EMERGENCY exit from unix process:

CTRL+c

RESET a linux server the hard way, total downtime is around a minute:

sudo reboot

See who is logged on to the server and what they are doing:

w

or to see a full list use:

last

See all the last commands used on the server:

history

To move up the folder tree:

cd ..

To show what is in a folder:

ls

To move into a folder:

cd foldername

To check size of files in a folder in human readable format:

du -h foldernamehere

See size of files in a folder (first move to the folder using cd and cd..).  Note there is a space between the du and the star.

du *

To download a particular file from a given location:

wget locationoffilewithfiletypeatend

Example: wget http://www.google.com/favicon.ico

To remove a folder and all files contained within (WARNING BE CAREFUL!):

rm -r foldername

To remove a file (WARNING can be dangerous, be sure that you are in the correct folder and everything is typed correctly before hitting return!)

rm filename

To rename a folder:

mv oldfoldername newfoldername

To rename a file:

mv oldfilename newfilename

To unzip, ungzip and untar a file:

tar xzf filename.tar.gz

To tar and gzip a folder:

$ tar -zcf filenameyouwant.tar.gz folderyouwanttotar

Example: tar -zcf test.tar.gz usr/bin/

-z: Compress archive using your gzip program
-c: Create an archive
-f: Archive File name

In UNIX the period (.) means the current directory.

To move a file up one directory (The ../ means up one folder):

mv myfilename.extensionoffile ../

To move up two folders then down into another folder:

mv filename.extension ../../Newdirectory

To chmod and change permissions on a file (744 is the permissions code):

chmod 744 filename.extension

To copy a file:

cp -i oldfilename newfilename

 

Change owner of file:

chown root error.log

Change group of file:

chgrp GROUPNAME FILENAME.EXTENSION

for example: chgrp root error.log

 

To create a file:

touch error.log

 

To restart a server:

sudo /etc/init.d/apache2 restart

 

See CPU loads and how long the server has been up:

uptime

See general, real time CPU and process information:

top

To exit the top command screen just press q and it will go back to the command prompt part where you can type anything.

See free memory:

free -m

 

Some external resources used to make this guide:

Toubleshooting a linux server

Tagged with:
 

Leave a Reply

Your email address will not be published.


5 + 1 =

Set your Twitter account name in your settings to use the TwitterBar Section.