Linux Commands frequently used by Linux Sysadmins – Part 1
What are some Linux commands used by Sysadmins and power users daily? In this article, I’ve listed 10 such commands frequently used. Suggestions and feedback are welcome. Also, see Part 2, Part 3, Part 4, and Part 5.
Some people consider Linux a complicated operating system geared toward expert users only. However, as a free and open-source operating system, Linux is geared toward all users. Allowing end-users and admins access to understanding as much or as little as they desire.
Whether you are entirely new to Linux or an experienced admin,
you’ll use these commands frequently. (Part 1 of 5)
As such, the commands listed below should help you better navigate, manage, and search Linux systems. The Linux commands listed below are also helpful in grabbing more information when troubleshooting. These command-line tips apply to all Linux systems and distros on virtual and physical machines.
1. List and show all IP addresses associated with all network interfaces.
You may know this as the much 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 recursive, -a
to include hidden files or -l
to use a per-line listing format. The cd
command 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 usage. Use -h
to print sizes in powers of 1024 (e.g., 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 ...
Also popular is the du
command. Used to estimate file space usage under a particular directory or files on the system.
4. Display memory usage.
Use -h
to show all output fields automatically scaled to the shortest three-digit unit and display the units of 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 using ;
.
;
Example:
sudo apt update ; apt upgrade
Then optionally, you can add the final command to a bash script.
6. Find large files.
Or install ncdu
and execute from the 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 PIDs. PIDs are displayed as decimal numbers 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 the ps
command in part 3.
8. Show a listing of the last logged-in users.
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 a 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, grep the word printf:
grep printf /path/filename.txt
For example, find previously used commands which include systemctl
history | grep systemctl
For example, find the last login(s) for username:
last | grep username
Last week, a reader posted a comment on a recent blog post requesting that some articles be a bit more beginner-friendly and quick and to the point. With this feedback in mind, this article serves as part 1 of 5.
Next – Linux Commands frequently used by Linux Sysadmins – Part 2 >
See also:
Quick tip:
If you want to check the IP address quickly without any additional information, you can use
ip -br a
command.These are great and awesome resources. I found this as I am writing a new RUST crate to be published. GitHub - trinib/Linux-Bash-Commands: :godmode: Ultimate list of Linux bash commands, cheatsheets and resources and it has all the commands for the system administration.
Just to keep handy in case you forgot something, no one can remember everything all the time.
if anyone has been using this, i think can. I have been using this since many years : https://tldr.sh and this helps write the bash and system commands faster. Updating my stack and removed the old ones and finalizing the move with the current stack so thought that this might help you all as all have been searching.
If you use Neovim for the code then these are the repositories to follow: GitHub - rockerBOO/awesome-neovim: Collections of awesome neovim plugins. GitHub - altermo/vim-plugin-list: A list of vim/neovim plugins(/extensions for plugins) and https://neovimcraft.com
Evening from Germany,
Gaurav
Yes, I’ve been using tldr and ChatGPT for command line help.
Thats great, I use tldr and not chatGPT till now but will see later if needed. You should be always open to learning something new and this is how it goes. Right now i am finishing RUST so reading RUST everyday and at the same time, writing code in GO and Python.
There is a better implementation tealdeer-rs · GitHub and it is RUStT based and so fast.
Gaurav