DEV Community

Sospeter Mong'are
Sospeter Mong'are

Posted on

Essential Commands Linux Command Cheat Sheet

Introduction

Linux is a versatile and powerful operating system, and its command line is where the magic happens. Whether you’re a beginner or a pro, this cheat sheet, complete with examples and emojis, will guide you through essential commands. Let’s dive in! πŸŽ‰


1. πŸ“‚ File and Directory Management

πŸ“œ List Files

ls
Enter fullscreen mode Exit fullscreen mode

Lists files and directories.

Detailed Listing with Hidden Files:

ls -la
Enter fullscreen mode Exit fullscreen mode
  • -l: Detailed listing
  • -a: Show hidden files

πŸšͺ Change Directory

cd <directory>
Enter fullscreen mode Exit fullscreen mode

Example:

cd /home/user/Documents
Enter fullscreen mode Exit fullscreen mode

πŸ“ Create a Directory

mkdir <directory_name>
Enter fullscreen mode Exit fullscreen mode

Example:

mkdir my_project
Enter fullscreen mode Exit fullscreen mode

πŸ—‘οΈ Remove a File or Directory

To remove a file:

rm <file>
Enter fullscreen mode Exit fullscreen mode

Example:

rm example.txt
Enter fullscreen mode Exit fullscreen mode

To remove a directory:

rm -r <directory>
Enter fullscreen mode Exit fullscreen mode

Example:

rm -r old_directory
Enter fullscreen mode Exit fullscreen mode

πŸ“‹ Copy Files

cp <source> <destination>
Enter fullscreen mode Exit fullscreen mode

Example:

cp file.txt /home/user/backup/
Enter fullscreen mode Exit fullscreen mode

βœ‚οΈ Move or Rename Files

mv <source> <destination>
Enter fullscreen mode Exit fullscreen mode

Example:

mv old_name.txt new_name.txt
Enter fullscreen mode Exit fullscreen mode

2. πŸ“ File Viewing and Editing

πŸ‘€ View File Contents

cat <file>
Enter fullscreen mode Exit fullscreen mode

Example:

cat /etc/passwd
Enter fullscreen mode Exit fullscreen mode

πŸ“– Page Through a File

less <file>
Enter fullscreen mode Exit fullscreen mode

Example:

less largefile.log
Enter fullscreen mode Exit fullscreen mode

✏️ Edit Files

nano <file>
Enter fullscreen mode Exit fullscreen mode

Example:

nano notes.txt
Enter fullscreen mode Exit fullscreen mode

3. πŸ‘₯ User Management

πŸ”„ Switch Users

su <username>
Enter fullscreen mode Exit fullscreen mode

Example:

su root
Enter fullscreen mode Exit fullscreen mode

πŸ‘€ Add a New User

sudo useradd -m <username>
Enter fullscreen mode Exit fullscreen mode

Example:

sudo useradd -m alice
Enter fullscreen mode Exit fullscreen mode

Set a password:

sudo passwd alice
Enter fullscreen mode Exit fullscreen mode

πŸ—‘οΈ Delete a User

sudo userdel <username>
Enter fullscreen mode Exit fullscreen mode

Example:

sudo userdel alice
Enter fullscreen mode Exit fullscreen mode

4. πŸ” Permissions

πŸ› οΈ Change File Permissions

chmod <mode> <file>
Enter fullscreen mode Exit fullscreen mode

Example:

chmod 755 script.sh
Enter fullscreen mode Exit fullscreen mode
  • 755: Owner can read/write/execute; others can read/execute.

πŸ™‹ Change File Ownership

sudo chown <user>:<group> <file>
Enter fullscreen mode Exit fullscreen mode

Example:

sudo chown alice:users file.txt
Enter fullscreen mode Exit fullscreen mode

5. 🌐 Networking

🌍 Check IP Address

ip addr
Enter fullscreen mode Exit fullscreen mode

πŸ“‘ Ping a Host

ping <hostname_or_ip>
Enter fullscreen mode Exit fullscreen mode

Example:

ping google.com
Enter fullscreen mode Exit fullscreen mode

⬇️ Download a File

wget <url>
Enter fullscreen mode Exit fullscreen mode

Example:

wget https://example.com/file.tar.gz
Enter fullscreen mode Exit fullscreen mode

6. πŸ’Ύ Disk and System

πŸ’Ώ Check Disk Space

df -h
Enter fullscreen mode Exit fullscreen mode

πŸ“Š View Disk Usage

du -sh <directory>
Enter fullscreen mode Exit fullscreen mode

Example:

du -sh /var/log
Enter fullscreen mode Exit fullscreen mode

πŸš€ Monitor System Processes

top
Enter fullscreen mode Exit fullscreen mode

🧠 Check Memory Usage

free -h
Enter fullscreen mode Exit fullscreen mode

πŸ”„ Reboot or Shutdown

Reboot:

sudo reboot
Enter fullscreen mode Exit fullscreen mode

Shutdown:

sudo shutdown now
Enter fullscreen mode Exit fullscreen mode

7. πŸ“¦ Package Management

πŸ“₯ Install a Package (Debian/Ubuntu)

sudo apt install <package>
Enter fullscreen mode Exit fullscreen mode

Example:

sudo apt install curl
Enter fullscreen mode Exit fullscreen mode

🧹 Remove a Package

sudo apt remove <package>
Enter fullscreen mode Exit fullscreen mode

Example:

sudo apt remove apache2
Enter fullscreen mode Exit fullscreen mode

πŸ“ˆ Update System

sudo apt update && sudo apt upgrade
Enter fullscreen mode Exit fullscreen mode

8. πŸ” Searching and Grep

πŸ”Ž Find Files

find <directory> -name "<file_name>"
Enter fullscreen mode Exit fullscreen mode

Example:

find / -name "*.log"
Enter fullscreen mode Exit fullscreen mode

πŸ“‚ Search Text in Files

grep "<text>" <file>
Enter fullscreen mode Exit fullscreen mode

Example:

grep "error" /var/log/syslog
Enter fullscreen mode Exit fullscreen mode

9. πŸ“¦ Archiving and Compression

πŸ“¦ Create a Tar Archive

tar -cvf archive.tar <directory>
Enter fullscreen mode Exit fullscreen mode

πŸ“‚ Extract a Tar Archive

tar -xvf archive.tar
Enter fullscreen mode Exit fullscreen mode

πŸ’¨ Compress Files

gzip <file>
Enter fullscreen mode Exit fullscreen mode

Example:

gzip logs.txt
Enter fullscreen mode Exit fullscreen mode

10. ⚑ Miscellaneous

πŸ“ Print Working Directory

pwd
Enter fullscreen mode Exit fullscreen mode

⏱️ Check System Uptime

uptime
Enter fullscreen mode Exit fullscreen mode

🧹 Clear Terminal Screen

clear
Enter fullscreen mode Exit fullscreen mode

Shortcut: Ctrl + L


πŸ›  Bonus Tips

  • Change directory ownership recursively:
  sudo chown -R user:group /path/to/directory
Enter fullscreen mode Exit fullscreen mode
  • Make a script executable:
  chmod +x /path/to/script.sh
Enter fullscreen mode Exit fullscreen mode
  • Detailed filesystem info:
  df -Th
Enter fullscreen mode Exit fullscreen mode

πŸŽ‰ Conclusion

Mastering these commands will transform your Linux experience, making tasks faster and smoother. Whether it’s file management, networking, or system monitoring, this cheat sheet covers all the essentials.

Keep exploring, and happy Linuxing! 🐧

Top comments (0)