DEV Community

Software Developer
Software Developer

Posted on

50 Most Useful Linux Commands 🐧

1. System Information

Command Description Example
uname -a Displays system information uname -a
hostname Shows the system’s hostname hostname
lsb_release -a Shows Linux distribution info lsb_release -a
uptime Shows how long the system has been running uptime
top Displays running processes in real-time top
htop Interactive version of top (needs install) htop
free -h Displays memory usage free -h
df -h Shows disk usage in human-readable format df -h
du -sh Shows total disk usage of a directory du -sh /home
cat /proc/cpuinfo Displays CPU information cat /proc/cpuinfo

2. File and Directory Management

Command Description Example
ls Lists files and directories ls -l
cd Changes directory cd /var/log
pwd Prints current working directory pwd
mkdir Creates a new directory mkdir myfolder
rmdir Removes an empty directory rmdir oldfolder
rm Removes files or directories rm file.txt, rm -rf folder/
cp Copies files or directories cp file1.txt /home/user/
mv Moves or renames files mv old.txt new.txt
touch Creates an empty file touch newfile.txt
find Searches for files or directories find / -name "*.txt"

3. File Viewing and Editing

Command Description Example
cat Displays file content cat file.txt
less Views file content one page at a time less file.txt
head Shows first 10 lines of a file head file.txt
tail Shows last 10 lines of a file tail -f log.txt
nano Opens text editor nano file.txt
vi or vim Opens VI editor vi file.txt
grep Searches for text inside files grep "error" log.txt
sort Sorts lines in a file sort names.txt
uniq Removes duplicate lines uniq names.txt
wc Counts lines, words, characters wc -l file.txt

4. Permissions and Ownership

Command Description Example
chmod Changes file permissions chmod 755 script.sh
chown Changes file owner and group chown user:group file.txt
whoami Shows current user whoami
id Displays user ID and group ID id
sudo Runs command as superuser sudo apt update

5. Networking Commands

Command Description Example
ping Checks connectivity to a host ping google.com
ifconfig Shows network interfaces (deprecated) ifconfig
ip addr Shows network configuration ip addr
netstat -tuln Lists open ports netstat -tuln
ss -tuln Modern replacement for netstat ss -tuln
curl Transfers data from URLs curl https://example.com
wget Downloads files from web wget http://example.com/file.zip
scp Copies files over SSH scp file.txt user@remote:/path
ssh Connects to remote server via SSH ssh user@ipaddress
traceroute Shows route packets take to host traceroute google.com

6. Package Management

Command Description Example
apt update Updates package lists (Debian/Ubuntu) sudo apt update
apt upgrade Upgrades all packages sudo apt upgrade
apt install Installs a package sudo apt install nginx
apt remove Removes a package sudo apt remove nginx
yum install Installs package (RHEL/CentOS) sudo yum install httpd

7. Process and Job Management

Command Description Example
ps Displays running processes ps aux
kill Kills a process by PID kill 1234
killall Kills all processes by name killall firefox
bg Resumes job in background bg
fg Brings job to foreground fg
jobs Lists background jobs jobs
nice Sets process priority nice -n 10 command
top Real-time process view top
htop Interactive process monitor htop

8. Compression and Archiving

Command Description Example
tar Archives files tar -cvf archive.tar folder/
tar -xvf Extracts archive tar -xvf archive.tar
gzip Compresses files gzip file.txt
gunzip Decompresses files gunzip file.txt.gz
zip Creates zip file zip archive.zip file1 file2
unzip Extracts zip file unzip archive.zip

9. Disk and File System Management

Command Description Example
mount Mounts a filesystem mount /dev/sdb1 /mnt
umount Unmounts filesystem umount /mnt
fsck Checks and repairs file system fsck /dev/sda1
blkid Shows block device info blkid
lsblk Lists block devices lsblk

10. Time and Scheduling

Command Description Example
date Displays current date/time date
cal Shows calendar cal
crontab -e Edits scheduled cron jobs crontab -e
at Runs commands at a specific time at 5pm

11. System Shutdown and Reboot

Command Description Example
shutdown Shuts down system sudo shutdown now
reboot Reboots system sudo reboot
halt Stops all processes sudo halt
logout Logs out current user logout

Bonus Commands (Hidden Gems)

Command Description Example
history Shows command history history
alias Creates command shortcuts alias ll='ls -la'
echo Prints text to terminal echo "Hello Linux"
man Displays manual for a command man ls
clear Clears terminal screen clear

Final Thoughts

Learning these Linux commands helps you:

  • Work faster with terminal automation
  • Troubleshoot systems like a pro
  • Manage files, users, and networks with ease

Pro Tip: Combine commands using pipes (|) and logical operators (&&, ||) to perform complex tasks efficiently.
Example:

ps aux | grep nginx && echo "Nginx is running!"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)