Basic Unix Commands

Below are some basic Unix commands which you may need to use frequently.
Note: The Quotes “‘” may have a different Unicode value and you may need to replace them with the good ones.

Listing the files and folders along with their sizes in long format :

$ ls -lrth

Listing all the files including the hidden files :

$ ls -al

Copy a file to a location :

$ cp /path/of/sourceFile /path/of/destinationFile

Copy directory recursively :

$ cp -R /path/of/source /path/of/destination

Move file or directory (You can use -i option to have a prompt before overwriting any existing file) :

$ mv /path/of/source /path/of/destination

Remove a file :

$ rm nameOfFile

Remove recursively :

$ rm -R nameofDir

Check filesystem :

$ df -h

Modify permissions :

$ chmod -options nameOfDir

I commonly use $ chmod 755 nameOfDir

Find the current directory :

$ pwd

Make a new directory :

$ mkdir dirName

Search a String in the files of the current directory ignoring case (-i) :

$ grep -i “string” *.log

Using grep recursively ignoring case (-i) :

$ grep -ri ‘string’ /folder/path

To check who has logged on :

$ who

To find your username :

$ whoami

Change password :

$ passwd

Kill a process forcefully (Replace PID with the actual number) :

$ kill -9 PID

Show the disk usage of files and directories. Useful while cleaning the server :

$ du -ksh *

To monitor a file getting updated runtime :

$ tail -f /filepath/filename

To switch to root user from normal user :

$ sudo su – root

Design a site like this with WordPress.com
Get started