Linux Commands Frequently Used by Linux Sysadmins – Part 1

What are some Linux commands used daily by sysadmins and power users? In this article, I have listed 10 such commands that are used frequently. Suggestions and feedback are welcome. Also, see Part 2, Part 3, Part 4 and Part 5.

Some consider Linux to be a complex operating system, designed only for expert users. However, as a free and open-source operating system, Linux is really geared towards all users. Allowing both end-users and admins to understand as much or as little as they wish.

Whether you are completely new to Linux or an experienced administrator,
You will find yourself using these commands over and over again. (Part 1 of 5)

As such, the commands listed below will help you navigate, manage and search Linux systems better. The Linux commands listed below are also useful in gaining more information during troubleshooting. These command-line tips apply to all Linux systems and distros on both virtual and physical machines.

1. List and show all IP addresses associated with all network interfaces.

You may know this as the longer command ip address show,

ip a

Example output:

[root@web ~]# ip a
...
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
...
inet xxx.xx.xxx.xx/32 brd xxx.xx.xxx.xx scope global eth0
...
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
...
inet 192.168.0.2/24 brd 192.168.0.255 scope global eth1

ip command cheat sheet, (PDF)

2. List non-hidden files and subfolders in the current directory.

Use -R for recursion, -a to include hidden files or -l To use the per-line listing format. cd Ordering is discussed in Part 2.

ls

Example output:

[root@web /]# ls -l
total 36
drwx--x--x. 5 root root 76 Aug 11 03:28 backup
lrwxrwxrwx. 1 root root 7 Oct 30 2019 bin -> usr/bin
dr-xr-xr-x. 5 root root 4096 Jun 26 05:45 boot
drwxr-xr-x. 20 root root 3120 Jun 6 06:07 dev
drwxr-xr-x. 99 root root 12288 Aug 12 07:40 etc
drwxr-xr-x. 8 root root 146 Feb 17 00:04 home
...

3. Display disk space usage.

Use -i To list inode information instead of block use . Use -h To print sizes in powers of 1024 (eg, 1023M).

df -h

Example output:

[user@server ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 17G 0 17G 0% /dev
/dev/mapper/root 313G 161G 153G 52% /
/dev/sdb1 1014M 266M 749M 27% /boot
...

is also popular du Permission. Used to estimate the file space usage under a particular directory or files on the system.

4. Display memory usage.

Use -h To automatically show all output fields in the smallest three digit unit and display the units of the print out. or use -m To display the amount of memory in Mebibytes.

free -m

Example output:

[root@web /]# free -h
total used free shared buff/cache available
Mem: 32G 2.0G 24G 1.6G 6.1G 28G
Swap: 16G 64M 16G
[root@web /]# free -m
total used free shared buff/cache available
Mem: 33016 2021 24746 1640 6248 28957
Swap: 16639 64 16575

5. Run multiple commands in one line by using ; ,

;

Example:

sudo apt update ; apt upgrade

Then optionally, you can add the last command to the bash script.

6. Search large files.

or install ncdu and execute from command line. Also, see the locate command in Part 3.

find [directory] -size [set minimum size]

Example:

find /home/ -size +1000000k

7. Display a tree of processes.

add -P To show PID. The PID is shown as a decimal number in parentheses after each process name.

pstree -P

Example output:

xxx@host:~$ pstree
systemd─┬─accounts-daemon───2*[{accounts-daemon}]
        ├─agetty
        ├─apache2───3*[apache2───31*[{apache2}]]
        ├─atd
        ├─cron
...
        ├─networkd-dispat───{networkd-dispat}
        ├─php-fpm7.4───5*[php-fpm7.4]
...

Also see ps Order in part 3.

8. Show list of users who were last logged in.

last

Example output:

[root@server ~]# last
root pts/0 xxx.xxx.xxx.xxx Wed Aug 12 08:29 still logged in 
root pts/0 xxx.xx.xxx.xx Wed Jul 29 10:52 - 12:13 (01:21) 
root pts/0 xxx.xx.xx.xx Mon Jul 27 23:11 - 00:10 (00:58) 
root pts/0 xxx.xxx.xx.xx Wed Jul 15 23:46 - 00:01 (00:15)

9. Show list of currently logged in user sessions.

w

Example output:

root@host:~$ w
13:08:25 up 72 days, 8:00, 1 user, load average: 0.01, 0.08, 0.08
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
xxxx-user pts/0 xxx.xx.xxx.xx 13:04 0.00s 0.00s 0.00s w

10. Search a file for a pattern of characters, then display all matching lines.

grep

for example:

grep [options] pattern [files]

For example, grep directory recursively:

grep -r "texthere" /home/

For example, the word printf grep:

grep printf /path/filename.txt

For example, find previously used commands that include systemctl

history | grep systemctl

For example, find the last login for username:

last | grep username

Last week, a reader posted a comment on a recent blog post requesting that some articles be a little more beginner-friendly and quick and to the point. With this reaction in mind, this article serves as part 1 of the multiplier, if deemed useful. If you want to see additional articles like this, please leave a note in the comments section below.

Next – Linux Commands Frequently Used by Linux Sysadmins – Part 2 >

See all:

Leave a Comment