Linux Commands and Shell Scripts

Top 10 Advanced Commands for Middle Level Linux Users


1.Command: Find

Search for files in the given directory, hierarchically starting at the parent directory and moving to sub-directories.

[email protected]:~# find -name *.sh


Note: The `-name‘ option makes the search case sensitive. You can use the `-iname‘ option to find something regardless of case. (* is a wildcard and searches all the file having extension ‘.sh‘ you can use filename or a part of the file name to customize the output).

[email protected]:~# find -iname *.SH ( find -iname *.Sh / find -iname *.sH)


[email protected]:~# find -name *.tar.gz


Note: The above command searches for all the file having extension ‘tar.gz‘ in root directory and all the sub-directories including mounted devices.

2.Command: grep

The ‘grep‘ command searches the given file for lines containing a match to the given strings or words. Search ‘/etc/passwd‘ for ‘tecmint‘ user.

[email protected]:~# grep copycookie /etc/passwd


Ignore word case and all other combination with ‘-i‘ option.

[email protected]:~# grep -i copycookie /etc/passwd


Search recursively (-r) i.e. read all files under each directory for a string ““.

[email protected]:~# grep -r “” /etc/

/etc/speech-dispatcher/modules/ivona.conf:#IvonaServerHost “”
/etc/mysql/my.cnf:bind-address =
/etc/apache2/mods-available/status.conf: Allow from ::1
/etc/apache2/mods-available/ldap.conf: Allow from ::1
/etc/apache2/mods-available/info.conf: Allow from ::1
/etc/apache2/mods-available/proxy_balancer.conf:# Allow from ::1
/etc/security/access.conf:#+ : root :
/etc/dhcp/dhclient.conf:#prepend domain-name-servers;
/etc/dhcp/dhclient.conf:# option domain-name-servers;
/etc/init/network-interface.conf: ifconfig lo up || true
/etc/java-6-openjdk/ localhost &
/etc/java-6-openjdk/ http.nonProxyHosts=localhost|
/etc/java-6-openjdk/ localhost &
/etc/java-6-openjdk/ ftp.nonProxyHosts=localhost|
/etc/hosts: localhost

Note: You can use these following options along with grep.

-w for word (egrep -w ‘word1|word2‘ /path/to/file).
-c for count (i.e., total number of times the pattern matched) (grep -c ‘word‘ /path/to/file).
–color for coloured output (grep –color server /etc/passwd).

3.Command: man

The ‘man‘ is the system’s manual pager. Man provides online documentation for all the possible options with a command and its usages. Almost all the command comes with their corresponding manual pages. For example,

[email protected]:~# man man

MAN(1) Manual pager utils MAN(1)

man – an interface to the on-line reference manuals

man [-C file] [-d] [-D] [–warnings[=warnings]] [-R encoding] [-L locale] [-m system[,…]] [-M path] [-S list] [-e extension] [-i|-I]
[–regex|–wildcard] [–names-only] [-a] [-u] [–no-subpages] [-P pager] [-r prompt] [-7] [-E encoding] [–no-hyphenation] [–no-justification] [-p
string] [-t] [-T[device]] [-H[browser]] [-X[dpi]] [-Z] [[section] page …] …
man -k [apropos options] regexp …
man -K [-w|-W] [-S list] [-i|-I] [–regex] [section] term …
man -f [whatis options] page …
man -l [-C file] [-d] [-D] [–warnings[=warnings]] [-R encoding] [-L locale] [-P pager] [-r prompt] [-7] [-E encoding] [-p string] [-t] [-T[device]]
[-H[browser]] [-X[dpi]] [-Z] file …
man -w|-W [-C file] [-d] [-D] page …
man -c [-C file] [-d] [-D] page …
man [-hV]

4.Command: ps

ps (Process) gives the status of running processes with a unique Id called PID.

[email protected]:~# ps

4170 pts/1 00:00:00 bash
9628 pts/1 00:00:00 ps

To list status of all the processes along with process id and PID, use option ‘-A‘.

[email protected]:~# ps -A

1 ? 00:00:01 init
2 ? 00:00:00 kthreadd
3 ? 00:00:01 ksoftirqd/0
5 ? 00:00:00 kworker/0:0H
7 ? 00:00:00 kworker/u:0H
8 ? 00:00:00 migration/0
9 ? 00:00:00 rcu_bh

Note: This command is very useful when you want to know which processes are running or may need PID sometimes, for process to be killed. You can use it with ‘grep‘ command to find customised output. For example,

[email protected]:~#ps -A | grep -i ssh

1500 ? 00:09:58 sshd
4317 ? 00:00:00 sshd

Here ‘ps‘ is pipelined with ‘grep‘ command to find customized and relevant output of our need.

5.Command: whereis

The ‘whereis‘ command is used to locate the Binary, Sources and Manual Pages of the command. For example, to locate the Binary, Sources and Manual Pages of the command ‘ls‘ and ‘kill‘.

[email protected]:~# whereis ls

ls: /bin/ls /usr/share/man/man1/ls.1.gz

[email protected]:~# whereis kill

kill: /bin/kill /usr/share/man/man2/kill.2.gz /usr/share/man/man1/kill.1.gz

Note: This is useful to know where the binaries are installed for manual editing sometimes.

6.Command: df

Report disk usages of file system. Useful for user as well as System Administrator to keep track of their disk usages. ‘df‘ works by examining directory entries, which generally are updated only when a file is closed.

[email protected]:~# df

Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 47929224 7811908 37675948 18% /
none 4 0 4 0% /sys/fs/cgroup
udev 1005916 4 1005912 1% /dev
tmpfs 202824 816 202008 1% /run
none 5120 0 5120 0% /run/lock
none 1014120 628 1013492 1% /run/shm
none 102400 44 102356 1% /run/user
/dev/sda5 184307 79852 94727 46% /boot
/dev/sda7 95989516 61104 91045676 1% /data
/dev/sda8 91953192 57032 87218528 1% /personal

7.Command: lpr

This command print files named on command line, to named printer.

[email protected]:~# lpr -P deskjet-4620-series 1-final.pdf

Note: The ‘lpq‘ command lets you view the status of a printer (whether it’s up or not), and the jobs (files) waiting to be printed.

8.Command: cmp

compare two files of any type and writes the results to the standard output. By default, ‘cmp‘ Returns 0 if the files are the same; if they differ, the byte and line number at which the first difference occurred is reported.

To provide examples for this command, lets consider two files:


[email protected]:~# cat file1.txt

Hi My name is copycookie


[email protected]:~# cat file2.txt

Hi My name is copycookie [dot] com

Now, let’s compare two files and see output of the command.

[email protected]:~# cmp file1.txt file2.txt

file1.txt file2.txt differ: byte 15, line 1


9.Command: mount

Mount is an important command which is used to mount a filesystem that don’t mount itself. You need root permission to mount a device.

First run ‘lsblk‘ after plugging-in your filesystem and identify your device and note down you device assigned name.

[email protected]:~# lsblk

sda 8:0 0 931.5G 0 disk
├─sda1 8:1 0 923.6G 0 part /
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 7.9G 0 part [SWAP]
sr0 11:0 1 1024M 0 rom
sdb 8:16 1 3.7G 0 disk
└─sdb1 8:17 1 3.7G 0 part

From this screen it was clear that I plugged in a 4 GB pendrive thus ‘sdb1‘ is my filesystem to be mounted. Become a root to perform this operation and change to /dev directory where all the file system is mounted.

[email protected]:~# su

[email protected]:~# cd /dev

Create a directory named anything but should be relevent for reference.

[email protected]:~# mkdir usb
Now mount filesystem ‘sdb1‘ to directory ‘usb‘.

[email protected]:~# mount /dev/sdb1 /dev/usb

Now you can navigate to /dev/usb from terminal or X-windows system and acess file from the mounted directory.

10.Command: wget

Wget is a free utility for non-interactive (i.e., can work in background) download of files from the Web. It supports HTTP, HTTPS, FTP protocols and HTTP proxies.

Download ffmpeg using wget

[email protected]:~# wget

–2020-10-11 10:55:00–
Resolving (…
Connecting to (||:80… connected.
HTTP request sent, awaiting response… 302 Found
Location: [following]
–2020-10-11 10:55:00–
Resolving (…
Connecting to (||:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 275557 (269K) [application/octet-stream]
Saving to: ‘ffmpeg-php-0.6.0.tbz2’

100%[===========================================================================>] 2,75,557 67.8KB/s in 4.0s

2020-10-11 10:55:00 (67.8 KB/s) – ‘ffmpeg-php-0.6.0.tbz2’ saved [275557/275557]



Related Articles