ls : List files/directories in a current directory, equivalent to dir command in dos/windows.
ls -al : Shows all files and directories with the details attributes for each file.

cd : Change directory
cd ~ : Change your directory to your home directory.
cd – : Change to the last directory you were in.

tail : Reads and display the end of the file
tail /var/www/me.txt : Display last 20 lines (by default) lines of the given file.
tail -f /var/www/me.txt : Watch the file continuously, while it’s being updated.
tail -400 /var/www/me.txt : Print last 400 lines of the file to the screen.

more : Open file one screen at a time.
more /etc/log.txt : Opens the file one screen at a time rather than all at once. Press Space to go to next page.

pico : easy to use file editor
pico /home/mysite/public_html/you.html : edit the you.html file from the public_html directory.

vi : popular editor in linux, have lots of features but harder to use
vi /home/mysite/public_html/you.html : edit the you.html from the public_html directory.

grep : looks for certain patterns in files
grep root /etc/passwd : shows all matches of root in /etc/passwd
grep -v root /etc/passwd : shows all lines that do not match root

touch : create an empty file
touch /home/mysite//public_html/new.html : create an empty file called new.html in the directory /home/mysite//public_html/

ln : create’s “links” between files and directories
ln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf : Now you can edit /etc/httpd.conf rather than the original. changes will affect the orginal, however you can delete the link and it will not delete the original.

rm : delete a file
rm filename.txt : Deletes filename.txt, It will confirm you before deleting file.
rm -f filename.txt : Deletes filename.txt without confirmation.
rm -rf tmp/ : Recursively deletes the directory tmp, and all files in it, including subdirectories.

last : shows who logged in with the time
last -20 : shows only the last 20 logins
last -20 -a : shows last 20 logins, with the hostname in the last field

netstat : shows all current network connections.
netstat -an : shows all connections to the server, the source and destination ips and ports.
netstat -rn : shows routing table for all ips bound to the server.

top : shows useful live system info
processes in a table format, memory information, uptime and other useful info. This is excellent for managing your system processes, resources and ensure everything is working fine and your server isn’t bogged down. top then type Shift + M to sort by memory usage or Shift + P to sort by CPU usage

ps: ps is short form of process status, equivalent to the top command. It’s used to show currently running processes with their PID.

A process ID is a unique number that identifies a process, with that you can kill or terminate a running program on your server (see kill command).
ps U username : shows processes for a certain user
ps aux : shows all system processes
ps aux –forest : shows all system processes like the above but organizes in a hierarchy that’s very useful!

file : attempts to guess what type of file a file is by looking at it’s content.
file * : prints out a list of all files/directories in a directory

du : shows disk usage.
du -sh : shows a summary of total disk space used in the current directory, including subdirectories.
du -sh * : same as above, but for each file and directory. helpful when finding large files taking up space.

wc : word count
wc -l filename.txt : tells how many lines are in filename.txt

cp : copy a file
cp filename filename.backup : copies filename to filename.backup
cp -a /home/mysite/old/* /home/mysite/new/ : copies all files, retaining permissions form one directory to another.

kill: terminate a system process
Syntax: kill -9 PID Examples: kill -9 431
Syntax: kill PID Examples: kill 10550

Written by Bala Krishna

Bala Krishna is web developer and occasional blogger from Bhopal, MP, India. He like to share idea, issue he face while working with the code.