The Linux command line can feel intimidating at first, but it is actually one of the most powerful and efficient ways to interact with your computer. This guide covers the 30 most important commands that every beginner should learn and practice.
File Navigation
# 1. pwd - Print working directory
pwd
# Output: /home/user
# 2. ls - List directory contents
ls # Basic listing
ls -la # Detailed listing with hidden files
ls -lh # Human-readable file sizes
# 3. cd - Change directory
cd /var/log # Go to specific directory
cd .. # Go up one level
cd ~ # Go to home directory
cd - # Go to previous directory
File Operations
# 4. cp - Copy files
cp file.txt backup.txt # Copy file
cp -r directory/ backup/ # Copy directory
# 5. mv - Move or rename files
mv old-name.txt new-name.txt # Rename
mv file.txt /other/directory/ # Move
# 6. rm - Remove files
rm file.txt # Remove file
rm -r directory/ # Remove directory
rm -i file.txt # Ask before removing
# 7. mkdir - Create directories
mkdir new-folder # Create directory
mkdir -p parent/child/grandchild # Create nested directories
# 8. touch - Create empty files
touch newfile.txt
Viewing File Contents
# 9. cat - Display entire file
cat config.txt
# 10. less - Page through file
less large-log-file.log
# Use arrows to scroll, q to quit
# 11. head - Show first lines
head -20 logfile.log
# 12. tail - Show last lines
tail -20 logfile.log
tail -f logfile.log # Follow new lines in real-time
Search and Filter
# 13. grep - Search for patterns
grep "error" logfile.log # Find lines containing "error"
grep -i "warning" logfile.log # Case insensitive
grep -r "TODO" /project/ # Search recursively
# 14. find - Find files
find /home -name "*.pdf" # Find by name
find / -size +100M # Find large files
find . -mtime -7 # Modified in last 7 days
# 15. which - Find command location
which python3
which nginx
Permissions and Ownership
# 16. chmod - Change file permissions
chmod 755 script.sh # rwxr-xr-x
chmod +x script.sh # Add execute permission
chmod 644 config.txt # rw-r--r--
# 17. chown - Change file ownership
sudo chown user:group file.txt
sudo chown -R www-data:www-data /var/www/
System Information
# 18. df - Disk space usage
df -h
# 19. du - Directory size
du -sh /var/log/
du -sh * # Size of each item in current dir
# 20. free - Memory usage
free -h
# 21. uname - System information
uname -a
# 22. uptime - System uptime
uptime
Process Management
# 23. ps - Show processes
ps aux
ps aux | grep nginx
# 24. top/htop - Real-time process monitor
top
htop
# 25. kill - Terminate a process
kill 12345
kill -9 12345 # Force kill
Networking
# 26. ping - Test connectivity
ping -c 4 google.com
# 27. curl - Transfer data
curl https://api.example.com
curl -O https://example.com/file.zip
# 28. ip/ifconfig - Network interfaces
ip addr show
ip route show
Text Processing and Pipes
# 29. echo - Print text
echo "Hello World"
echo $HOME
# 30. Pipes and redirection
ls -la | grep ".log" # Pipe output to grep
echo "text" > file.txt # Write to file (overwrite)
echo "more text" >> file.txt # Append to file
cat file.txt | sort | uniq # Chain commands
Practice Tips
- Open a terminal and practice each command daily
- Use the
mancommand to read manual pages:man ls - Create a practice directory and experiment freely
- Try combining commands with pipes
- Set up a Linux virtual machine if you are on Windows or Mac
The command line becomes comfortable with practice. Start with these 30 commands, use them daily, and you will be navigating Linux like a professional in no time.