# Linux Commands Every Architect Should Know

[Linux](https://www.linux.org/) is pervasive in software deployment architecture, and being a hands-on technologist with Linux helps in various ways. This article summarizes most of the commonly used Linux commands & utilities every architect should know. As each variant or distribution of Linux might have differences, there might be some variation as per Linux variants: Debian Linux, RHEL & CentOS, Oracle Linux, Ubuntu Linux, Alpine Linux, and Arch Linux.  
Before we start, use the below command to check Linux Kernel details:

```
 cat /etc/os-release* 
 uname -a
(* - except CentOS, which needs /etc/centos-release)
```

[![](https://vedcraft.com/images/2021/03/os-release-1.png)](https://vedcraft.com/images/2021/03/os-release-1.png)

For simplicity, Linux commands or utilities have been grouped together into 4 areas with **top 5 commands** along with popular params for convenience:

## #1 – Process Monitoring

-   [**top**](https://man7.org/linux/man-pages/man1/top.1.html) – To view CPU & memory usage information. _General guidance is Load Average should be similar to the number of cores for the system not under stress._You can also use newer version [htop](https://man7.org/linux/man-pages/man1/htop.1.html) command for more interactivity.  
    _Usage Example:_  
    

```
top -u <user> #user specific processes
Press M: sort by memory, P: sort process list by CPU usage, V: Forest view, R: for reversing the order
htop -u <user> #user specific processes 
```

-   **[ps](https://man7.org/linux/man-pages/man1/ps.1.html)** – Classic command to view list of running processes – Linux variants have different parameter options. Below examples are the most useful:  
    

```
ps auwwx #list all the processes with wider format & easy to remember
ps -ef | grep 'java' #to filter specific process
ps -ef | awk '{print $1}' | sed '/UID/d' | sort | uniq -c | sort -nr
#count running process under each user
```

-   **[kill](https://man7.org/linux/man-pages/man2/kill.2.html)** – Classic command for killing a running process. **[killall](https://man7.org/linux/man-pages/man1/killall.1.html)** is useful to kill all the processes by a name.  
    

```
kill -l #to list all available signals
kill -9 <pid> #SIGKILL signal to kill the process
killall top #kill all top processes; you can put any process name
```

-   **[lsof](https://man7.org/linux/man-pages/man8/lsof.8.html)**– List of Open Files by the process – very useful when debugging resources consumed by a process particularly when everything in Linux is a file. Note that it might not be installed by default in some variants (e.g. CentOS) and you need to install **“lsof”** package.  
    

```
lsof -u <username>  #list of files opened by a user
lsof -c <process> #list of files opened by a process named
lsof -p <pid> #list of files opened by PID
lsof -i #files opened by network
lsof -i :443 #to find the process/service listening on a port
```

-   **[fuser](https://man7.org/linux/man-pages/man1/fuser.1.html)** – shows the PIDs of processes using the specified files or file systems in Linux.  
    You need to install **_“psmisc”_** package before using this command – see installation section below for instruction as per Linux variant.  
    

```
fuser 80/tcp #find the process/service listening on a particular port by running the command 
fuser <filename> #to find out file being used by the 
```

## #2 – File Operations

-   [**tail**](https://man7.org/linux/man-pages/man1/tail.1.html) – for viewing the last part of files/logs, most commonly used parameter is _“tail -f”_
-   **[find](https://man7.org/linux/man-pages/man1/find.1.html)** – for searching the files. Commonly usage examples – [click here](https://www.tecmint.com/35-practical-examples-of-linux-find-command/):  
    

```
find . -name "*.log" #to find the log files in current directory & sub-directory 
find . -type f -name "*.java"  #to find all java file types
find . -type f -perm 0777 -print #to find files with 777 permissions
find / -type f -perm 0777 -print -exec chmod 555 {} \; #to find files with 777 permissions and replace with 555
find / -size +50M -size -100M #to find files between 50-100MB size
```

-   **[grep](https://man7.org/linux/man-pages/man1/grep.1.html)** – for searching pattern within file. [Click here](https://www.thegeekstuff.com/2009/03/15-practical-unix-grep-command-examples/) for different examples.

```
grep -i "linux" *.log #case insensitive search within log files
grep "REGEX" *.log #use any REGEX
grep -w "word" *.log #check for full word
grep -c "word" *.log #count the number of words matched
grep -v "word" *.log #invert the match to display non-matching
grep -r "word" *.log #to search recursively in all folders
grep -A 5 -i "word" *.log #display 5 lines after the match
```

-   **Others:** uniq sort diff cut ncat sed awk

##   
#3 – Network Monitoring

-   **[tcpdump](http://www.tcpdump.org/tcpdump_man.html)** – for analyzing network packet level details. Useful for packet-level inspection, detecting denial of service attacks by inspecting large packets or source, debug the source & destination generating traffic, etc.- tcpdump not port 22 and not port 25 (exclude SSH to avoid unnecessary info)  
    _Usage examples:_  
    

```
tcpdump udp #for capturing specific protocol dump; find list of protocols in /etc/protocols)
tcpdump -c10 -i eth1 -n -A port 80 #dumps in ASCII format with (-A) with specific port and exit after receiving 10 packets (-c))
tcpdump -l | tee dat #Make stdout line buffered. Useful if you want to see the data while capturing it
tcpdump -i eth0 host 10.122.19.222 #capture for specific IP address
tcpdump -s 0 -A -vv 'tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x47455420'  #capture only HTTP GET or POST only
```

1.  Note: If not installed, install “tcpdump” package (e.g. for Alpine Linux: _apk add tcpdump_). [Click here](https://www.redhat.com/sysadmin/troubleshoot-tcpdump) to read the troubleshooting article by RedHat and see 20 different examples by [clicking here](https://hackertarget.com/tcpdump-examples/).

-   **[netstat](https://man7.org/linux/man-pages/man8/netstat.8.html)** – Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships
-   **[traceroute](https://man7.org/linux/man-pages/man8/traceroute.8.html)** – print the route packets trace to network host
-   **[ss](https://man7.org/linux/man-pages/man8/ss.8.html)** – utility to investigate sockets (very useful to check socket stats)
-   **iperf** – utility to check network bandwidth between two systems. [Click here](https://www.cyberciti.biz/faq/how-to-test-the-network-speedthroughput-between-two-linux-servers/) to read the most useful link found for iperf.
-   **Others:** strace, mtr, dig, sar, ifconfig (prints ip address)

## #4 – Disk & Memory Monitoring

-   [**du**](https://man7.org/linux/man-pages/man1/du.1.html) / [**df**](https://man7.org/linux/man-pages/man1/df.1.html) – du (disk usage of the set of FILEs, recursively for directories), df (report file system disk space usage)
-   **[free](https://man7.org/linux/man-pages/man1/free.1.html)** – to find out free and used memory
-   [**iostat**](https://man7.org/linux/man-pages/man1/iostat.1.html) – for CPU stats and I/O stats for devices & partitions
-   **[mount](https://man7.org/linux/man-pages/man8/mount.8.html)** – to mount a file system
-   **[fdisk](https://man7.org/linux/man-pages/man8/fdisk.8.html)** – to manipulate disk partition

## Installing Package

Below commands are example of installing packages for different variations:

```
$ yum install <package> # RHEL/CentOS 
$ apt install <package>	# Debian/Ubuntu
$ apk add <package>     # Alpine Linux
$ dnf install <package> # Fedora
```

## Other Useful Commands

-   **[alias](https://ss64.com/bash/alias.html)** (for bash) – useful for creating shortcuts to frequently used commands
-   **[tree](https://www.howtoforge.com/linux-tree-command/)** – shows a visual representation of the files in a directory
-   **[watch](https://man7.org/linux/man-pages/man1/watch.1.html)** – run any command at regular intervals and displays the output
-   **[truncate](https://www.man7.org/linux/man-pages/man1/truncate.1.html)** – shrink or extend the size of a file to the specified size. For example, the below command will free up capacity quickly:

```
truncate -s 0 filename
```

-   **Security**:
    -   Check Certificate Expiry and other details using **[openssl](https://www.digicert.com/kb/ssl-support/openssl-quick-reference-guide.htm)** command

```
openssl x509 -in my-cert.pem -noout -issuer -subject -dates
```

-   **Top 10 commands** from bash history:

```
cat ~/.bash_history | sort |uniq -c|sort -nr|head -n 10
```

-   **[](https://man7.org/linux/man-pages/man1/systemctl.1.html)**[systemctl](https://man7.org/linux/man-pages/man1/systemctl.1.html)****– to control the running system and other services
-   **Miscellaneous:** mpstat, pmap, kill, iostat, vmstat, chkconfig, uptime (shows how long system is running), pidof, cal (shows calendar), zip, unzip, ssh, whatis (locate the binary), whereis (one-line man page), finger (short dump of info about a user), w (current user info), chown (change ownership of file), chmod (change permission of files & directories), locate (to find a file), ping (to check connectivity),nl (cat with line numbers)

To conclude, these commands/utilities help not only to troubleshoot but to understand the functions of Linux operating system. Even though you are using application performance monitoring (APM) tools, as a software architect you should know these expand the full-stack knowledge.

## **Linux Useful Websites**

-   [Linux.org](https://www.linux.org/) – for discussion, tutorial, and references
-   [Linux.com](https://www.linux.com/) – by Linux Foundation for latest news, articles & updates
-   [Linux Foundation](https://www.linuxfoundation.org/) – community-driven site focused on Opensource
-   [man7.org](https://man7.org/linux/man-pages/) – Linux Online Manual
-   [Linux Commands Cheatsheets](https://itsfoss.com/linux-commands-cheat-sheets/)
-   [Explain Shell](https://explainshell.com/) – Explains each part of the command (useful when trying to understand complex commands used together with parameters)
-   [nixCraft/cyberciti](https://www.cyberciti.biz/) – for Linux sysadmins
-   [Linux Today](https://www.linuxtoday.com/) – for latest news on Linux

## **Related Article**

-   [Free Docker & Kubernetes Courses for Application Architects](https://vedcraft.com/learning-paths/free-docker-kubernetes-courses/)
