Skip to main content

Command Palette

Search for a command to run...

Linux Commands

Published
β€’3 min read
Linux  Commands
S

SIH finalist 2K22 πŸš€ | πŸ’™Full Stack DeveloperπŸ’™,πŸ“’Learn in Public🌎,πŸ’–Open Source, Technical Writing ✍ 🟠 HungryπŸ˜‹ for MoreπŸ“š Knowledge 🀠

🐧 Linux Command Cheat Sheet: Essential Commands with Examples

Linux is a versatile and powerful operating system. The command line is your gateway to mastery. Here's your cheat sheet, packed with must-know commands and real-world examples, sprinkled with emojis to make learning fun! πŸš€


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