Linux  Commands

Linux Commands

ยท

3 min read

๐Ÿง 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

Did you find this article valuable?

Support Sujeet Vishvkarma by becoming a sponsor. Any amount is appreciated!

ย