30 Important Linux Commands With Examples

Basics and Frequently used Linux commands plays an important role when you are working as a DBA, Programmer, DevOPS, Admins, sysadmin, Cloud engineer and so on. Your works becomes easier when you already know the advanced Linux commands and which you are using it on your daily basis.

To Create Directory in Linux

[root@orahow ~]# mkdir directory_name

You can also provide path name to create a directory structure. This will create directories inside the directory.
[root@orahow ~]# mkdir -p app/oracle/19c/dbhome_1

To Check currently Working Directory

pwd command is used to check the currently working directory.
[root@orahow ~]# pwd
/scratch/orahow/app/oracle/19c/dbhome_1

To change Ownership of the Directory

[root@orahow ~]# chown -R owner:group directory_path or name
[root@orahow ~]# chown -R oracle:dba /scratch/orahow

To change File permission

[root@orahow ~]# chmod 777 filename
777 - read,write,execute for owner, group and others
[root@orahow ~]#  chmod 755 test
[root@orahow ~]#  ls -lrt test
-rwxr-xr-x 1 root root 3 Apr 11 13:42 test

To Remove Directories and its contents completely.

[root@orahow ~]# rm -rf directory_name
[root@orahow ~]# rm -f file_name     --to remove files

To see the contents of a file

[root@orahow ~]# cat file_name
[root@orahow ~]# cat directory_path/file_name

To see last n lines of the file
[root@orahow ~]# tail -10f  filename 

To see file contents in scrolling fashion
[root@orahow ~]# more filename

To Copy files and directories in Linux

[root@orahow ~]# cp file file_backup
[root@orahow ~]#  cp -rp source destination
[root@orahow ~]#nohup cp -rp E-BIZ E-BIZ_BACKUP & 

To find and remove fies older than x days

[root@orahow ~]# find /path/to/files* -mtime +30 -exec rm {} \;
+30 means older than 30 days, you can modify accordingly.

To compress or archive directories using tar

Below command will archive and create E-BIZ.tar files of E-BIZ directory.
[root@orahow ~]# tar -cvf E-BIZ.tar E-BIZ 

Below command will create E-BIZ.tar inside /export/backup/ folder in background
[root@orahow ~]# nohup tar -cvf /export/backup/E-BIZ.tar E-BIZ &

To check Connected Users in Linux

[root@orahow ~]# w

To Switch User in Linux

[root@orahow ~]# su - username

To Add User and Groups in Linux

To add a Group: Login as a root user.
[root@orahow ~]# groupadd -g <groupID> <group_name>
groupID- any numerical value and must be unique and non-negative
[root@orahow ~]# groupadd -g 1001 oinstall

To Add a user:
[root@orahow ~]# useradd <username> -b <user_directory> -g <group>

options used:
-s : user shell
-d : user directory
-c comment

Examples:
[root@orahow ~]# useradd oracle -b /app -g oinstall
[root@orahow ~]# useradd -s /bin/bash -m -d /export/home/oracle -c "developer" oracle

To see Running Process and Resource Usage in Linux

[root@orahow ~]# top

To find a running process in Linux

[root@orahow ~]# ps -ef|grep -i process_name
[root@orahow ~]# ps -ef|grep -i pmon
oracle 54421 1 0 Feb13 ? 00:07:54 ora_pmon_LS23HK
root 82163 81266 0 12:57 pts/0 00:00:00 grep -i pmon

To Kill a Process in Linux

[root@orahow ~]# kill -9 PID
[root@orahow ~]# kill -9 PID1, PID2, PID3

To check total, used and free disk space in Linux

[root@orahow ~]# df -h

Space utilization of currently working mount point.
[root@orahow ~]# df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/xvdb 473G 322G 127G 72% /scratch

To check space occupied by files and directories

[root@orahow ~]# du -sh *

To Check Memory Utilization in Linux

bash-4.1$ free -g

Command to Release Cache Memory

As a root user:
[root@orahow ~]# echo 3 > /proc/sys/vm/drop_caches
[root@orahow ~]# free -g

To check I/O wait on Linux

[root@orahow ~]# vmstat 2
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 1101864 25233460 102524 3206732 0 0 3 88 0 0 1 1 98 0 0
0 0 1101864 25241840 102532 3206764 0 0 0 112 1259 2331 0 0 100 0 0
0 0 1101864 25241888 102532 3206764 0 0 0 16 1180 2270 0 0 100 0 0
0 0 1101864 25242020 102540 3206756 0 0 0 50 1211 2292 0 0 100 0 0
0 0 1101864 25242044 102544 3206764 0 0 0 58 1180 2271 0 0 100 0 0

wa- check 2nd last column average wait. If wa value is greater than 20 then system is facing I/O related issue. Check the process and ask storage team or linux admin to check any disk related issues.
r - number of process waiting for runtime. 

To Reboot Linux remotely

[root@orahow ~]# shutdown -r now

To check Open Ports in Linux

[root@orahow ~]# netstat -tulpn | grep LISTEN
[root@orahow ~]# netstat -plnt | grep -i ':22'
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 5100/sshd
tcp 0 0 :::22 :::* LISTEN 5100/sshd

To show User and Group information for the current User or particular user

[root@orahow ~]# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),179(sfcb)

To Mount NFS Share in Linux

[root@orahow ~]# mount -t nfs source_hostname:path dest_directory
[root@orahow ~]# mkdir /DB_Backup
[root@orahow ~]# mount -t nfs hostname:/export/DB_Backup /DB_Backup

To mount automatically after reboot edit and add entry into fstab 
vi /etc/fstab
hostname:/export/DB_Backup /DB_Backup nfs defaults 0 0