Linux Commands — The Essentials

Akash Mahale
DevOps Dudes
Published in
5 min readFeb 17, 2021

The demand for cloud computing skills is on the rise as more and more companies are adopting cloud-based services. The focus is to move the on-premise servers to the cloud with the public or hybrid cloud architecture. The new-age IT works on the cloud and most of the cloud workload operates on the Linux operating system.

The fact is that most people are using Linux without even knowing it — whether on their smartphones, online when using Google, social media apps, GPS devices, e-commerce apps, or when using cloud storage for personal or business use. Thus, Linux skills become a key aspect for engineers working on any cloud technology. With several proprietary services being developed by the cloud providers, what remains the same across all of them is the Linux command-line interface (CLI). With that in mind, I have listed all the important commands, essential for system operations and configurations (file, network, processes, etc.)

1. System Commands :


uname -a ==> Displays information about the system
uname -r ==> Displays information of kernel release
date ==> Displays date (day, month, time, year)
cal ==> Displays calendar format
uptime ==> Displays how long the system is running and the load
hostname ==> Displays name of the host on the system
whoami ==> Displays who we are logged in as
last reboot ==> Displays history of system boots
sudo init 0 ==> Shut down the system
sudo init 6 ==> Reboots the system

2. Users Commands :

id ==> Displays active user id with login and group id
who ==> Shows who is logged into the system
sudo su ==> To become a super(root) user
last ==> Shows when and who last logged in the system
groupadd abc ==> Adds a group “abc” in the system
useradd xyz ==> Adds a user “xyz” in the system
userdel xyz ==> Deletes the user “xyz”

3. File Commands :

pwd ==> Displays the present working directory
ls -al ==> Displays information of all files in the directory
mkdir d1 ==> Creates a directory “d1”
rm -r d1 ==> Deletes the directory “d1” (recursively)
touch f1 ==> Creates a file “f1”
touch .f2 ==> Creates a hidden file “f2”
rm f1 ==> Deletes the file f1
cp f1 f2 ==> Copies content of file “f1” to file “f2”
cp -r d1 d2 ==> Copies content of directory “d1” tp directory “d2”
mv f1 f2 ==> Renames files or moves from source to destination
cat f1 ==> Displays content in the file
head f1 ==> Shows first 10 lines of the file
tail f1 ==> Shows last 10 lines of the file
gpg -c f1 ==> Encrypts file “f1” and is saved as .gpg file
gpg f1.gpg ==> Decrypts the file
wc ==> Shows the total bytes, words and lines in the file
locate f1 ==> Searches for all instances of the file “f1”

4. Compression/ Archives :
Note: Here, “abc” and “xyz” can be a directory or a file


tar cf abc.tar abc ==> Creates “abc.tar” containing “abc”
tar xvf abc.tar ==> Extracts the files from “abc.tar”
tar czf xyz.tar.gz xyz ==> Creates a tar of “xyz” gzip compression
gzip xyz ==> Compresses “xyz” and names it as “xyz.gz”

5. File Permissions :
Note : r=read, w=write, x=execute

File permission modes and corresponding octal numbers
chmod octalnumber f1 ==> Change the permission of the file “f1”
chowm owner f1 ==> Change owner of the file “f1”

6. Networking Commands :

ip addr show ==> Displays all network interfaces and ip address
ifconfig ==> Used to configure and display network interfaces
ping host ==> Sends echo request to the host (ip, url)
ping -c4 host ==> Sends 4 echo request to the host (ip, url)
ping -s 84 host ==> Sends echo request of specified bytes eg.84bytes
netstat ==> Displays n/w connections, routing tables, etc.
netstat -tupln ==> Displays all active listening ports
nslookup www.xyz.com ==> Queries the DNS to obtain domain name or IP
traceroute www.xyz.com ==> Displays data transmission route

7. Process Related Commands :
Note: A foreground process is any command or task we run directly and wait for it to complete. A background process is a process for which the shell does not wait to end before it can run more processes.

ps ==> Shows all active processes with the process ids (PIDs)
top ==> Displays all running processes
bg ==> Resumes suspended jobs without bringing them to foreground
fg ==> Brings recent job to foregorund
ps aux | grep ‘telnet’ ==> Finds PID of processes related to telnet
sudo kill -9 PID ==> Kills process of mentioned PID
sudo lsof -i : PORT ==> Maps port number and PID on that port

8. Disk Usage :

df -h ==> Shows free space on the mounted file system
sudo fdisk -l ==> Displays disk partitions, size and types
du -sh ==> Displays disk usage of current directory
du -ah ==> Displays disk usage of the entire system
mount device-path mount-point ==> Mounts a external device on system

9. Switching Directories :

cd /abc ==> Change to “abc” directory
cd ==> Switches to $HOME directory
tree ==> Displays content of the directory in a tree like format

10. Logins :

telnet host ==> Connects to remote host using telnet port
ssh user@host ==> Securely connects to remote host — ssh protocol
ssh — p PORT user@host ==> SSH using a specific port

11. Hardware Commands :

lscpu ==> Displays entire architecture information of the CPU
dmesg ==> Displays hardware and boot messages
lsblk ==> Shows information about blocked devices on the system
free -m ==> Displays used and free memory
lspci -tv ==> Shows PCI(Peripheral Component Interconnect) devices
lsusb -tv ==> Shows USB devices
sudo hdparm -tT /dev/sda ==> Does a read speed test on sda

12. File Transfer :

scp source_file_name username@destination_host:destination_directory
==> Securely copies source file to specified destination and
destination folder

13. Integrity Check :
Note: The integrity of the files can be checked with md5sum or sha256sum. For example, if 2 files produce the same message digest, means the 2 files are the same if the digest varies, which means, the files have tampered.

md5sum f1 ==> Produces for file “f1” — a 128-bits digest
sha256sum f1 ==> Compute and check SHA256 message digest

Conclusion :
There are several Linux commands, but the most commonly used and important Linux commands are mentioned in this blog. These can be used to write interactive Bash scripts, to write automation task scripts, and perform system-level tasks with ease. Suggestions are most welcomed.

--

--

Akash Mahale
DevOps Dudes

Cloud Engineer, DevOps - GCP | Azure | Kubernetes | DevOps