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
Lists files and directories.
Detailed Listing with Hidden Files:
ls -la
-
-l
: Detailed listing -
-a
: Show hidden files
πͺ Change Directory
cd <directory>
Example:
cd /home/user/Documents
π 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 a File
less <file>
Example:
less largefile.log
βοΈ Edit Files
nano <file>
Example:
nano notes.txt
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:
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
π§ 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
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
Shortcut: Ctrl + L
π Bonus Tips
- Change directory ownership recursively:
sudo chown -R user:group /path/to/directory
- Make a script executable:
chmod +x /path/to/script.sh
- Detailed filesystem info:
df -Th
π 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)