Linux is a powerful operating system, and its command line is the key to unlocking its full potential. Here's your Linux command cheat sheet with examples and a touch of fun 🎉 using emojis for easier navigation!
1. 📂 File and Directory Management
📜 List Files
ls
- List all files in a directory.
Example:
ls -la
-
-l
: Detailed listing -
-a
: Include hidden files
🚪 Change Directory
cd <directory>
Example:
cd /home/user/Documents
- Move to the "Documents" directory.
📁 Create a Directory
mkdir <directory_name>
Example:
mkdir my_project
🗑️ Remove a File or Directory
To remove a file:
rm <file>
Example:
rm example.txt
To remove a directory:
rm -r <directory>
Example:
rm -r old_directory
📋 Copy Files
cp <source> <destination>
Example:
cp file.txt /home/user/backup/
✂️ Move or Rename Files
mv <source> <destination>
Example:
mv old_name.txt new_name.txt
2. 📝 File Viewing and Editing
👀 View File Contents
cat <file>
Example:
cat /etc/passwd
📖 Page Through File
less <file>
Example:
less largefile.log
✏️ Edit Files
nano <file>
Example:
nano notes.txt
- Open the "notes.txt" file for editing in Nano.
3. 👥 User Management
🔄 Switch Users
su <username>
Example:
su root
👤 Add a New User
sudo useradd -m <username>
Example:
sudo useradd -m alice
Set a password for the user:
sudo passwd alice
🗑️ Delete a User
sudo userdel <username>
Example:
sudo userdel alice
4. 🔐 Permissions
🛠️ Change File Permissions
chmod <mode> <file>
Example:
chmod 755 script.sh
-
755
: Owner can read/write/execute; others can read/execute.
🙋 Change File Ownership
sudo chown <user>:<group> <file>
Example:
sudo chown alice:users file.txt
5. 🌐 Networking
🌍 Check IP Address
ip addr
📡 Ping a Host
ping <hostname_or_ip>
Example:
ping google.com
⬇️ Download a File
wget <url>
Example:
wget https://example.com/file.tar.gz
6. 💾 Disk and System
💿 Check Disk Space
df -h
📊 View Disk Usage
du -sh <directory>
Example:
du -sh /var/log
🚀 Monitor System Processes
top
- Real-time view of system processes.
🧠 Check Memory Usage
free -h
🔄 Reboot or Shutdown
Reboot:
sudo reboot
Shutdown:
sudo shutdown now
7. 📦 Package Management
📥 Install a Package (Debian/Ubuntu)
sudo apt install <package>
Example:
sudo apt install curl
🧹 Remove a Package
sudo apt remove <package>
Example:
sudo apt remove apache2
📈 Update System
On Debian/Ubuntu:
sudo apt update && sudo apt upgrade
8. 🔍 Searching and Grep
🔎 Find Files
find <directory> -name "<file_name>"
Example:
find / -name "*.log"
📂 Search Text in Files
grep "<text>" <file>
Example:
grep "error" /var/log/syslog
9. 📦 Archiving and Compression
📦 Create a Tar Archive
tar -cvf archive.tar <directory>
📂 Extract a Tar Archive
tar -xvf archive.tar
💨 Compress Files
gzip <file>
Example:
gzip logs.txt
10. ⚡ Miscellaneous
📍 Print Working Directory
pwd
⏱️ Check System Uptime
uptime
🧹 Clear Terminal Screen
clear
Suggestions From comments by @schelp :
- ls
ls -ltrha (to bring the lastest files/dirs that had modifications.
- cd "", to enter in directories with that had an space into their names, like:
cd "/home/schelp/my files"
ls -ltrha "/home/schelp/my files"
- df -h (known a little bit more of the filesystem used, maybe its a good idea)
df -Th
One of the shortcuts that I like is: @schelp
- to clear the terminal screen
crtl + l
Suggestion from comment @xinitd :
- Change directory ownership recursively:
chown -R user:froup /path/to/directory
- Just add executable flag to file
chmod +x /path/to/script.sh
Conclusion
🎉 Mastering these commands will make your Linux journey smooth and efficient. From file management to networking, this cheat sheet covers essential tasks.
Do you have a favorite Linux command that isn’t here? Share it in the comments below! 👇
Written by: @eshanized
Contributor 1: @schelp
Contributor 2: @xinitd
Top comments (13)
Nice work, dude!
Maybe, you can add some like:
One of the shortcuts that I like is:
Sure bro! I will modify this❤️
Good job! Here my suggestions:
Changing directory ownership recursively:
Adding
executable
flag to file:I have added your writing also. Checkout! Thanks for contributing! Do follow my project on GitHub: github.com/Snigdha-OS
Thanks for sharing
Thanks for appreciating ! Do follow my project on GitHub: github.com/Snigdha-OS ❤️
Nice post!
Thanks for appreciating ! Do follow my project on GitHub: github.com/Snigdha-OS
what is the difference between chmod +x /path/to/script.sh and chmod u+x /path/to/script.sh ?
chmod +x /path/to/script.sh
is used when you want to make the script executable for all users e.g groups and it is equivalent toa+x
-a stands for all. on the other sideu+x
is used when you want to give permission for owner only. in details you can say likechmod +x
=rwxr-xr-x
andchmod u+x
=rwxr--r--
. Thank You for the question.@schelp I have added your writing also. Checkout! Thanks for contributing! Do follow my project on GitHub: github.com/Snigdha-OS
Nice
Thanks for appreciating ! Do follow my project on GitHub: github.com/Snigdha-OS
Some comments may only be visible to logged-in visitors. Sign in to view all comments.