The Ultimate Linux Command
Cheat Sheet: Mastering Linux for
Interviews and Real-World
Applications
Linux skills are essential for any software engineer, system administrator, or DevOps
professional. The ability to efficiently navigate the Linux command line can not only make you
a more efficient problem solver but also set you apart in technical interviews. To truly master
Linux, you need to go beyond memorizing commands—you need to understand their context,
use, and execution.
In this post, I’ve compiled an extensive list of essential Linux commands, along with practical
examples, that are crucial for both day-to-day work and interview preparation. Let's get
started!
1. Basic File System Navigation
Understanding the file system structure is critical in Linux. Here are some commands you’ll
need every day:
pwd: Prints the current directory.
ls: Lists files and directories.
ls -l: Provides detailed information, including file permissions and sizes.
cd: Changes directories. Use ~ for the home directory.
Examples
$ pwd
/home/user
$ ls
Documents Downloads Pictures
$ ls -l
drwxr-xr-x 2 user user 4096 Nov 10 08:00 Documents
-rw-r--r-- 1 user user 2048 Nov 10 08:00 file1.txt
$ cd /home/user/Documents
$ cd ..
$ cd ~
Interview Tip: Expect questions on navigating the Linux file system and understanding file
permissions.
2. File Manipulation: Creating, Copying, Moving, and Deleting
Files
The basics of file management are essential for daily tasks and troubleshooting:
touch: Creates a new empty file.
cp: Copies files.
mv: Moves or renames files.
rm: Removes files.
Examples
$ touch newfile.txt
$ cp file1.txt /tmp/
$ mv file1.txt backup.txt
$ rm backup.txt
Interview Tip: Expect practical tests where you'll have to create, move, and delete files on a
Linux system.
3. Working with Directories: Manage Your Folders
Directories are just as important as files. You’ll need commands to create, list, and navigate
them:
mkdir: Creates a new directory.
ls -d */: Lists only directories.
rmdir: Removes an empty directory.
Examples
$ mkdir newdir
$ ls -d */
$ rmdir newdir
4. Permissions and Ownership
Understanding file permissions is crucial. Here's how you can manage them:
chmod: Changes file permissions.
chown: Changes file ownership.
Examples
$ ls -l file1.txt
-rw-r--r-- 1 user user 2048 Nov 10 08:00 file1.txt
$ chmod 755 file1.txt
$ chown user:group file1.txt
Interview Tip: Be prepared to explain how file permissions work, especially the use of r, w, x,
and numeric values (e.g., 755).
5. Disk Usage and File System Management
To manage disk space and keep systems running smoothly, these commands come in handy:
df -h: Shows available disk space.
du -sh: Shows the disk usage of a specific directory.
fdisk -l: Lists all partitions.
Examples
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 20G 30G 40% /
$ du -sh /home/user
2.5G /home/user
$ fdisk -l
6. Searching for Files and Data
Searching through large directories or files is something every developer needs to do
frequently:
find: Searches for files based on different criteria.
grep: Searches for a specific pattern inside files.
locate: Finds files by name, faster than find.
Examples
$ find / -name "*.log"
$ grep "error" /var/log/syslog
$ locate file.txt
7. Process Management
Managing processes and ensuring the smooth running of systems is critical:
ps aux: Lists all running processes.
top: Shows dynamic real-time process information.
kill: Sends a signal to terminate a process by PID.
pkill: Kills processes by name.
Examples
$ ps aux
$ top
$ kill 1234
$ pkill apache2
Interview Tip: You might be asked to find and kill a specific process using its PID.
8. Networking Commands
Knowing how to troubleshoot and monitor network connections is crucial for any system
administrator or developer:
ping: Checks connectivity to a remote host.
ifconfig: Shows network interfaces and their IP addresses.
netstat: Shows network connections and listening ports.
ssh: Connects securely to a remote machine.
Examples
$ ping google.com
$ ifconfig
$ netstat -tuln
$ ssh user@host
9. User Management
In multi-user systems, you'll often need to add, remove, or manage users:
useradd: Creates a new user.
passwd: Changes a user's password.
userdel: Deletes a user.
Examples
$ useradd newuser
$ passwd newuser
$ userdel newuser
10. Archiving and Compression
When handling backups or preparing large datasets, compression and archiving tools are
essential:
tar -czvf: Creates a compressed archive.
unzip: Extracts zip files.
gzip: Compresses a file.
Examples
$ tar -czvf archive.tar.gz /home/user
$ unzip file.zip
$ gzip file1.txt
11. System Monitoring and Performance Tuning
Knowing how to monitor your system’s health is key for optimizing performance:
vmstat: Gives a snapshot of system performance.
iostat -x: Provides detailed I/O statistics.
free -h: Shows memory usage.
Examples
$ vmstat 1
$ iostat -x
$ free -h
12. Backup and Recovery
You never want to lose data. These commands will help you create backups and restore them:
rsync: Often used for syncing data between directories or servers, with options for
backup.
Examples
$ cp -r /important/data /backup/
$ rsync -avz /source/ /destination/
13. Package Management (For Debian-Based and RPM
Systems)
Installing and managing packages on Linux is essential for keeping your system up-to-date:
apt: For Debian-based systems (e.g., Ubuntu).
yum: For RPM-based systems (e.g., CentOS).
Examples
$ sudo apt update
$ sudo apt upgrade
$ sudo apt install vim
$ sudo yum update
$ sudo yum install vim
14. Scheduling Tasks with Cron
Scheduling recurring tasks is easy with cron:
Example
$ crontab -e
0 2 * * * /usr/bin/python3 /home/user/scripts/backup.py
This runs the script backup.py every day at 2 AM.
15. System Services
Managing system services and ensuring they are running is critical for maintaining server
uptime:
systemctl: Used to manage services on systems with systemd.
Examples
$ systemctl status apache2
$ systemctl start apache2
$ systemctl enable apache2
$ systemctl stop apache2
16. Disk Partitioning and File Systems
Partitioning disks and managing filesystems is essential for configuring storage systems:
fdisk: Used for disk partitioning.
mkfs: Formats the partition with a file system.
Examples
$ fdisk /dev/sda
$ mkfs.ext4 /dev/sda1
17. Important Interview Preparation Tips
From an interview perspective, you may be asked about:
File System Hierarchy: Know where logs, binaries, and configuration files are located.
Basic Networking: Test connectivity using ping, troubleshoot with netstat.
Disk Usage: Check free space, monitor system performance.
Security: Understand file permissions and user management.
Conclusion
Mastering Linux commands is not just about memorization—it’s about understanding how
and when to use them. From file management to system optimization, these commands form
the backbone of any Linux-based infrastructure.
Now, take these commands, run them on your system, and start practicing! Whether you're
preparing for interviews or just looking to improve your Linux skills, consistency is key.