UNIX & LINUX Commands: List of UNIX / LINUX Commands Cheat Sheet

UNIX & LINUX Commands: List of UNIX / LINUX Commands Cheat Sheet

UNIX and LINUX are the open source operating systems that adopt command user interface and GUI (Graphical User Interface) to control executing various applications and organizing the file/directory.

UNIX and LINUX are the light-weight operating systems that are mostly employed using commands. Although these operating systems have been modified to be utilized with simple Graphical user interface, using command is very assistive and powerful. Getting through all the UNIX and LINUX commands is very difficult. Here, this blog comes with the comprehensive list of mostly employed commands with examples.

Let’s explore the directory of the Command lines

Grep Command (searching command)

Grep Command is used to search any expression, file or directory

Below are some examples

$ grep -i “Adroit” prac_file
This command-line search word “the” in “prac_file”

$ grep -r “kush” *
This command-line search the string “kush” recursively

$ grep -A 3 -i “iit” prac_text
This Command-line shows the line containing “iit” along the three lines

Awk Command (organizing record in file)

Awk Command can be used to present the data in record form.

$ awk ‘{print $1,$2;}’ Student.txt
This command shows the data of specified field in Student record

$awk -F ‘:’ ‘$3==$4’ passwd.txt
This Command-line shows the line having the Same UID and GID

$ awk ‘!($1 in array) { array[$1]; print }’ temp
This command-line displays the distinct record on the basis of the data in 1st record

Tar Command( create archive file )

Tar Command is used to grouping multiple files into single archive file.

$ tar tvf archive_file.tar
This command-line is used to view the archive file

$ tar xvf archive_name.tar
This command-line extracts the file from archive file “archive_name.tar”

$ tar cvf archive_first.tar dirname/
This command-line creates the archive file “archive_first.tar” of directory name

Find Command (searching file)

Find command is used to search the file in any directory.

$ find -iname “iam.txt”
This instruction finds file according to the given name

$ find ~ -empty
This instruction search all the files that are empty in the home directory

$ find -iname “stud.txt” -exec md5sum {} \;
This command-line runs the command on searched file

Sed Command (Special Editor)

Sed Command is used to edit the file smartly.

$ sed -n ‘1!G;h;$p’ file.txt
This will show all the content in reverse order

$sed ‘s/.$//’ filename
This will transform dos file format to UNIX file format

$ sed ‘/./=’ thegeekstuff.txt | sed ‘N; s/\n/ /’
This command-line puts the number line for all the line in file

Ssh command line ( Running program on remote System)

Ssh command line is used to login to remote system and execute the program on the system.

ssh -l Dev remotehost.system.com
This will login to the Remote host

ssh -v -l Dev remotehost.example.com
This instruction debug the ssh client

scp Localexample.txt root@examplehost.com:/recipient/directory/
This instruction transfers the file from local host to the remote host

Diff command examples (describe the difference between two text)

Diff command is used to spot the difference between contents in the files

$ diff -w name_example.txt name_example2.txt
Here, this instruction output the difference of content line wise in both the file.

Ls command examples (listing the file and directory)

ls command is employed to define the list of file/directory.

$ ls -1
This instruction displays one file per line

$ ls –lh
This command-line shows the file with the details with memory size

$ ls -ltr
This script will show the file list according to last modified date

Pwd command (print working directory)

Pwd command displays the local directory where we are working.

$ pwd
This instruction print the details regarding currently working the localhost

Xargs command ( bind two command)

Xargs command is used to bind the two command and execute them

# find / -name *.jpg -type f -print | xargs tar -cvzf sample.tar.gz
This code first collect the list jpg file type put them into archive file

# cat url-list.txt | xargs wget –c
This script Download all the url in url-list.txt file

Sort command (Display organize list/content in the file or file name)

Sort command presents the contents in the sorted manner.

$ sort file.txt
This command line organizes the file in the ascending manner

$ sort-r file.txt
This script shows the file in descending order

Vim command(editor to the file)

Vim command is the fast editor for the file.

$ vim +100 file.txt
This command jumps the cursor to the 100th line of the file

$ vim -R home/content
This instruction opens the file in read only mode

Export command (environment variable setting)

Export command is used to create/set environment variable.

$ export env_var=1
This code creates the environment variable env_var and set this variable to 1

Shutdown command ( turn off the system)

Shutdown command switch off the system and power

# shutdown -h now
This command switches off the system and turns the power off

# shutdown -r now
This instruction re-boots the system

Ftp command (connect to remote server)

Ftp command connect the local host with remote server.

$ ftp ftp.remote.org
This command links the local system to remote server (ftp.remote.org)

Unzip command (extract zipped file)

Unzip command is used to extract and present compressed file content.

$ unzip example.zip
This script extracts example.zip file

$ unzip -l example.zip
This script opens the example.zip without extracting the content

Bzip2 command (creating bzip file)

Bizip2 command convert and de-convert file bzip file.

$ bzip2 example.txt
This code converts simple file to bzipped file

$bzip2 -d example.txt.bz2
This instruction reconverts bzipped file to previous file

CD command (change directory)

CD command is used to change the directory or jumps from one file to another.

cd –
this instruction jumps two directory backward.

cd ..
this script used to go back one directory backward

Gzip command (compress the size of file)

Gzip command use to compact the size of the file.

$ gzip example.txt
This coding helps to compact the example.txt

$ gzip -d example.txt.gz
This line-of-code instructs to decompress the example.txt file

Service command (process various services)

Service command used to control the execution various services.

#service –status-all
This instruction states the status of all the services

# service ssh status
This command-line presents status of particular service

Free command (inform about memory usage)

Free command present the status of memory usage by various processes.

This instruction informs about the status memory utilized by the process such as “how much memory is free and how much is utilized”

Top command

Top command displays the processor status for the maximum programs running

$ top -u example
This command displays the most CPU intensive task of “example” user

Kill command (to cease the running process)

To stop the process, there is need of kill command. But,the process-id is required to refer the process.

$ ps -ef | grep vim
dev 7241 7222 9 20:40 pts/2 00:00:00 vim

$ kill -9 7241

The above instruction first get id of the process that is 7241 and then kill the process

PS command (Showing running process status)

To access information regarding the live process on the system ps command is assistive.

$ ps -ef | more
This instruction display the current process on the system

$ ps -efH | more
This command line shows all currently running process, but in tree structure or hierarchical way

DF command (showing disk-space utilization)

DF command is used to display the disk utilization by various process during execution.

$ df –h
This instruction shows the utilized memory in GB units

$ df -k
This instruction displays the utilized memory in Kilobytes

RM command (removing the files)

RM command is used to remove the files and directories.

$ rm -r example
This command recursively removes all the files under “example” directory

$ rm -i file*
This instruction states the name of the file and then asks for confirmation before removing it.

$ rm -i filename.txt
This command-line asks for the confirmation prior to the deletion of the file.

MV command (renaming file)

MV command is used to move the file or rename the file.

$ mv -i file1 file2
This command-line renames the file1 to file2. If file 2 exists,then it will ask for confirmation to overwrite it.

$ mv -v file1 file2
This instruction details about the events happens during file renaming.

Cat command (viewing file content)

cat command is used to print file content on the screen.

$ cat ex_file1 ex_file2
This instruction displays the multiple file simultaneously

$ cat -n /example/file.conf
This instruction shows file content by giving number at every line.

CP command(copying file)

CP command is used for copying source file to destination directory/file.

$ cp -i file1 file2
This instruction copies the file 1 to file 2. If file 2 exist, then it will prompts for confirmation.

$ cp -p file1 file2
This instruction copies file1 to file 2 and defining the file with same attributes such as mode and ownership.

Chmod command (changing mode)

chmod command is used to change the permission attribute of the file.

$ chmod ug+rwx file.txt
This instruction changes the mode of the file so that it can be completely accessed by user & group

$ chmod -R ug+rwx file.txt
This instruction recursively changes the permission mode of all file in directory

$ chmod g-rwx file.txt
This instruction revokes all the granting permission on “file.txt”

Mount command (mounting the file system)

Mount command is used to mount the file or arrange the file in tree hierarchy mode.

# mount /dev/sdb1 /ex_file
This instruction mounts the file in the ex_file directory. The ex_file must be created first.

Passwd command (changing password)

Passwd command is used to modify password of the user.

$ passwd
This instruction asks for the old password , then updates the password according to the user.

# passwd USERNAME
This command-line changes the password of username. It can only be utilized by super user of the system.

# passwd -d USERNAME
This command-line disables the password of the specified user mentioned by USERNAME

Chown command (changing owner/group)

chown command is used the change the owner and group who are linked to the file in various permissible mode.

$ chown kush:dev examplefile.sh
This instruction converts user to Kush and group to dev of file examplefile.sh

$ chown -R kush:dev /home/oracle
This command-line does the same, but recursively

Ifconfig command (configuring network)

Ifconfig command is used to configure the network attributes on the Linux platform.

$ ifconfig -a
This instruction line shows all the configuration of network interface

$ ifconfig eth0 down
This instruction turns down the specified network.

$ ifconfig eth0 up
This instruction starts up the specified network

Mkdir command (creating directory)

mkdir used to create directory or directory of directory.

$ mkdir ~/temp
This command line used to create directory for the file

$ mkdir -p dir1/dir2/dir3/dir4/
This instruction creates the directory of directory or nested directory

Whatis command (describing command)

Whatis command used to describe the command such what the command do and what are its attributes.

$ whatis cat
This instruction describes the command “cat”

Whereis command (knowing command location)

Whereis command displays the location of specified command existence.

$ whereis ls
This instruction displays the command “ls” location the output of the this instruction will be “ls: /bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz”

$ whereis -u -B /tmp -f ls
This instruction states the location from where the command can be executed

Uname command (getting important information)

Uname command is used to get important information such as Kernel name, processor type Host name etc

$ uname -a
This instruction displays the kernel name, all the system regarding information.

Less command (shortening huge description)

Less command is employed to display information in short form or important part of description can be viewed. This command is mostly utilized in viewing the log file.

$ less example.log
This command-line lessen the size of content at “example.log” file

CTRL+F – forward one window
CTRL+B – backward one window

When you open the file using less command, then the above mentioned control will help in exploring the content page-wise

Man command(displaying manual page)

Man command is used the display the content consisting of manual that is published with eight descriptions such as daemons ,General commands, System administration commands ,System calls, C library functions, File formats ,Special files (usually devices, those found in /dev) and drivers, and conventions, Games and screen saver and miscellaneous.

$ man crontab
This command-line will display the manual page of “crontab” command

Tail command (printing the content on the basis of line)

Tail command is used to print the content of the file according to the number of line mentioned in the attributes.

$ tail fileexample.txt
This instruction will display the last 10 line of the content in the file

$ tail -n N filename.txt
This instruction will show the N number of lines in the content of “filename.txt”.

Ping command (displaying the networking status)

Ping command displays the status of the network.

$ ping -c 5 gmail.com
This instruction will ping the remote host “gmail.com” by sending 5 packets.

SU command (Switch to Different User)

SU command login to different user by entering password and Username while super user does not need to enter password.

This instruction switches the user to specified “USERNAME”

This command-line executes the script named “SHELLNAME” at specified UserPage

Yum command(updating program using to maintain the system)

Yum command used to update and install the program to maintain the system.

$ yum install package
This instruction installs package on the system

$ yum update package
This instruction updates the package on the system.

$ yum remove package
This command-line removes the package

Date command( setting the system date)

Date command used to set the system time and date.

# date -s “01/31/2010 23:59:53”
This syntax will set the data and time.

Locate command (spotting the specific file)

Locate command is to instantaneously search the location of specified file.

$ locate example ab
This command shows the directory structure of the specified file

Mysql command ( \connecting the database)

Mysql command is used to bridge the gap between mysql client to mysql server (even running on the remote server).

$ mysql -u root -p
This instruction will connect to mysql database at local server

$ mysql -u root -p -h
This instruction is used to connect the mysql database at remote server and it will prompt for the password of the database

Wget command (downloading the element)

Wget command is used to download the music, software and many other item at the system.

$ wget -O example.zip http://www.vim.org/scripts/download_script.php?src_id=7701
This command-line downloads and stores the item by different name

$ wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.1.tar.gz
This command-line simply downloads the file with the given name.

Rpm command (managing software packages)

Rpm command is used to manage (install, update, verify, query, erase) the software packages.

# rpm -ivh httpd-2.2.3-22.0.1.el5.i386.rpm
This syntax installs apache on the system

# rpm -ev httpd
This syntax un-installs and removes apache from the system

Crontab command(running the program at background)

Crontab command executes the program at the background and you can also see the specific user entry at crontab.

# crontab -u dev -l
This instruction will show the entry by user “dev” at crontab

*/10 * * * * /home/kush/check-disk-space
This will schedule the task at background for every 10 minutes

UNIX & LINUX Commands: List of UNIX / LINUX Commands Cheat Sheet


It is believed that this comprehensive list of LINUX/UNIX commands with example will definitely help you in learning to execute LINUX & UNIX operating system at ease. If you find any UNUX & Linux command missing in this list that is mostly used, then do share with comment section given below or through the guest post. Stay connected with our blog for next updates.

Enjoyed this video?
UNIX & LINUX Commands: List of UNIX / LINUX Commands Cheat Sheet
"No Thanks. Please Close This Box!"