Linux commands form the foundation of system administration, automation, and DevOps workflows. Mastering these commands enables efficient server management, file processing, and task automation across any infrastructure environment.
This article demonstrates 50 essential Linux commands organized by practical use cases. You will implement file management workflows, process monitoring techniques, and system administration patterns used in production environments.
Prerequisites
- Ubuntu 24.04 machine with sudo access
- Terminal or SSH access to the system
- Basic understanding of command-line interfaces
- Text editor installed (vim, nano, or emacs)
Navigate the Linux File System
Identify Your Location
Display your current username:
$ whoami
Show the current working directory:
$ pwd
Clear the terminal screen while preserving command history:
$ clear -x
Navigate Between Directories
Change to a specific directory:
$ cd /var/log
Return to your home directory:
$ cd ~
Move up one directory level:
$ cd ..
Navigate multiple levels up:
$ cd ../../..
List Directory Contents
Display files in the current directory:
$ ls
Show detailed file information:
$ ls -l
Include hidden files (starting with .):
$ ls -la
List contents of a specific directory without changing location:
$ ls -la /etc/nginx/
Manage Files and Directories
Create Directory Structures
Create a single directory:
$ mkdir project
Create multiple directories simultaneously:
$ mkdir src tests docs
Build nested directory structures:
$ mkdir -p project/src/components/ui
Create and Manage Files
Generate empty files:
$ touch README.md
Create multiple files at once:
$ touch index.html style.css script.js
Remove Files and Directories
Delete files with verbose output:
$ rm -v oldfile.txt
Remove empty directories:
$ rmdir empty-folder
Delete directories with contents:
$ rm -r project-backup
Remove files interactively for safety:
$ rm -i sensitive-data.txt
Copy and Move Operations
Copy files:
$ cp config.yaml config.yaml.backup
Copy entire directories:
$ cp -r /var/www/html /home/user/backup
Move or rename files:
$ mv draft.txt final-report.txt
Move files to different directories:
$ mv *.log /var/log/archive/
Process File Contents
View File Contents
Display entire file contents:
$ cat /etc/hosts
Show first 20 lines of a file:
$ head -n 20 access.log
Display last 50 lines:
$ tail -n 50 error.log
Monitor log files in real-time:
$ tail -f /var/log/syslog
Search Within Files
Find specific text in a file:
$ grep "ERROR" application.log
Search with line numbers:
$ grep -n "timeout" server.log
Search recursively through directories:
$ grep -r "TODO" ./src
Case-insensitive search with context:
$ grep -i -C 3 "warning" *.log
Analyze File Differences
Compare two configuration files:
$ diff config.old config.new
Show differences side-by-side:
$ diff -y file1.txt file2.txt
Generate unified diff output:
$ diff -u original.conf modified.conf
Process Data with Pipes and Filters
Count and Sort Operations
Count lines, words, and bytes:
$ wc -l access.log
Sort file contents numerically:
$ sort -n numbers.txt
Remove duplicate lines:
$ sort data.txt | uniq
Count occurrences of unique items:
$ cat usernames.txt | sort | uniq -c | sort -nr
Combine Commands with Pipes
Count files in a directory:
$ ls -1 | wc -l
Find and display large files:
$ find . -type f -size +10M | xargs ls -lh
Extract unique IP addresses from logs:
$ grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' access.log | sort | uniq
Manage System Resources
Monitor Disk Usage
Check disk space:
$ df -h
Find directory sizes:
$ du -h --max-depth=1 /var
Identify largest directories:
$ du -h /home | sort -hr | head -10
Monitor Processes
View running processes:
$ ps aux
Display resource-intensive processes:
$ top
Find specific processes:
$ ps aux | grep nginx
Terminate processes:
$ kill -TERM 1234
Kill processes by name:
$ killall -KILL chrome
Manage Background Tasks
Run commands in background:
$ find / -name "*.log" -mtime +30 &
View background jobs:
$ jobs
Bring job to foreground:
$ fg 1
Send job to background:
$ bg 1
Handle File Permissions and Ownership
View Permissions
Display detailed file permissions:
$ ls -la /etc/passwd
Change Ownership
Modify file owner:
$ sudo chown ubuntu:www-data index.html
Change ownership recursively:
$ sudo chown -R deploy:deploy /var/www/app
Modify Permissions
Grant execute permission:
$ chmod +x deploy.sh
Set specific permissions using octal notation:
$ chmod 644 config.ini
Remove write permission for group and others:
$ chmod go-w sensitive.txt
Archive and Compress Files
Create Archives
Bundle files into tar archive:
$ tar -cf backup.tar documents/
Create compressed archive:
$ tar -czf backup.tar.gz documents/
Extract Archives
Extract tar archive:
$ tar -xf backup.tar
Extract to specific directory:
$ tar -xzf backup.tar.gz -C /restore/
List archive contents:
$ tar -tzf backup.tar.gz
Compress Individual Files
Compress file and keep original:
$ gzip -k largefile.log
Decompress files:
$ gunzip compressed.gz
Search for Files and Directories
Find by Name
Locate all JavaScript files:
$ find . -name "*.js"
Case-insensitive search:
$ find /home -iname "*config*"
Find by Type and Size
Find directories only:
$ find /var -type d -name "log*"
Locate large files:
$ find / -type f -size +100M
Find by Time
Files modified in last 24 hours:
$ find . -mtime -1
Files older than 7 days:
$ find /tmp -mtime +7 -exec rm {} \;
Optimize Command-Line Productivity
Create Command Aliases
Define temporary alias:
$ alias ll='ls -la'
Make aliases permanent:
$ echo "alias gs='git status'" >> ~/.bashrc
$ source ~/.bashrc
Use Environment Variables
Display system PATH:
$ echo $PATH
Show current user:
$ echo $USER
Leverage Shell Expansions
Create multiple files with patterns:
$ touch test_{1..5}.txt
Use wildcards effectively:
$ rm *.tmp
Match single characters:
$ ls data_?.csv
Manage System Security
Switch Users
Change to another user:
$ su - deploy
Execute commands with elevated privileges:
$ sudo systemctl restart nginx
Monitor System Access
Check logged-in users:
$ who
View command history:
$ history | tail -50
Search command history:
$ history | grep docker
Conclusion
These 50 Linux commands provide the foundation for efficient system administration and DevOps workflows. Regular practice with these commands develops muscle memory for rapid troubleshooting and automation tasks.
Implement these commands in your daily operations to build proficiency. Combine them with shell scripting to create powerful automation solutions that scale across any Linux environment.
Top comments (1)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.