Posted on: January 19, 2025 Posted by: rahulgite Comments: 0

Linux commands are used to interact with the operating system’s shell. Below is a categorized list of essential Linux commands with explanations and practical examples.


1. File and Directory Management

ls

  • Description: Lists files and directories in the current directory.
  • Usage: ls
  • Options:
    • ls -l: Detailed list with permissions, size, owner, etc.
    • ls -a: Includes hidden files.

cd

  • Description: Changes the current directory.
  • Usage: cd /path/to/directory
  • Options:
    • cd ~: Changes to the home directory.
    • cd ..: Moves up one directory level.

pwd

  • Description: Prints the current working directory.
  • Usage: pwd

mkdir

  • Description: Creates a new directory.
  • Usage: mkdir new_directory
  • Options:
    • mkdir -p: Creates parent directories if they don’t exist.

rm

  • Description: Removes files or directories.
  • Usage: rm file.txt
  • Options:
    • rm -r: Removes directories recursively.
    • rm -f: Forces deletion without confirmation.
    • rm -i: Prompts before deletion.

mv

  • Description: Moves or renames files and directories.
  • Usage: mv old_name new_name
  • Options:
    • mv -i: Prompts before overwriting files.

find

  • Description: Searches for files and directories.
  • Usage: find /path -name "*.txt"

2. File Content Viewing and Editing

cat

  • Description: Displays the content of a file.
  • Usage: cat file.txt

less

  • Description: Views file content one screen at a time.
  • Usage: less file.txt

nano

  • Description: A simple text editor for editing files.
  • Usage: nano file.txt

vim

  • Description: A powerful text editor with extensive features.
  • Usage: vim file.txt
  • Tips:
    • Press i to enter insert mode.
    • Use :wq to save and exit.

grep

  • Description: Searches for patterns in files.
  • Usage: grep "pattern" file.txt
  • Options:
    • grep -i: Case-insensitive search.
    • grep -r: Searches recursively in directories.

3. Permissions and Ownership

chmod

  • Description: Changes file or directory permissions.
  • Usage: chmod 755 file.txt
  • Options:
    • chmod -R: Applies changes recursively.

chown

  • Description: Changes file ownership.
  • Usage: chown user:group file.txt
  • Options:
    • chown -R: Changes ownership recursively.

umask

  • Description: Sets default permissions for new files and directories.
  • Usage: umask 022

4. Process Management

ps

  • Description: Displays active processes.
  • Usage: ps
  • Options:
    • ps aux: Shows all processes with detailed information.
    • ps -ef: Displays processes in full format.

top

  • Description: Monitors system processes in real-time.
  • Usage: top
  • Tips:
    • Press q to quit.
    • Use k to kill a process.

kill

  • Description: Terminates a process by its PID.
  • Usage: kill -9 PID

htop

  • Description: An interactive process viewer (more user-friendly than top).
  • Usage: htop

bg and fg

  • Description: Moves jobs to the background or foreground.
  • Usage: bg %1 fg %1

5. Networking Commands

ping

  • Description: Tests connectivity to a host.
  • Usage: ping google.com

curl

  • Description: Transfers data from or to a server.
  • Usage: curl http://example.com
  • Options:
    • curl -o: Saves the output to a file.

wget

  • Description: Downloads files from the web.
  • Usage: wget http://example.com/file.zip

netstat

  • Description: Displays network connections and routing tables.
  • Usage: netstat -tuln

ss

  • Description: Displays detailed socket statistics (modern alternative to netstat).
  • Usage: ss -tuln

6. Disk Management

df

  • Description: Shows disk space usage.
  • Usage: df -h

du

  • Description: Shows disk usage of files and directories.
  • Usage: du -sh directory

lsblk

  • Description: Lists information about block devices.
  • Usage: lsblk

fdisk

  • Description: Partition management tool.
  • Usage: fdisk /dev/sda

7. System Monitoring Commands

uptime

  • Description: Displays system uptime, number of users, and load average.
  • Usage: uptime

free

  • Description: Displays system memory usage.
  • Usage: free -h

vmstat

  • Description: Reports system performance statistics like CPU, memory, and I/O.
  • Usage: vmstat 1 5
  • Options:
    • 1 5: Refreshes every second for 5 iterations.

iostat

  • Description: Displays CPU and I/O statistics.
  • Usage: iostat

sar

  • Description: Collects, reports, and saves system activity information.
  • Usage: sar -u 1 3

mpstat

  • Description: Monitors CPU usage by processors.
  • Usage: mpstat

dstat

  • Description: Combines multiple monitoring tools into one.
  • Usage: dstat

8. Archiving and Compression

tar

  • Description: Archives files and directories.
  • Usage: tar -cvf archive.tar file1 file2
  • Options:
    • -xvf: Extracts an archive.

gzip

  • Description: Compresses files.
  • Usage: gzip file.txt

gunzip

  • Description: Decompresses .gz files.
  • Usage: gunzip file.txt.gz

zip

  • Description: Creates compressed archives.
  • Usage: zip archive.zip file1 file2

unzip

  • Description: Extracts files from a .zip archive.
  • Usage: unzip archive.zip

7z

  • Description: Compresses and extracts .7z archives.
  • Usage: 7z a archive.7z file1 file2

xz

  • Description: Compresses files into .xz format.
  • Usage: xz file.txt

9. Package Management

apt (Debian/Ubuntu)

  • Description: Installs, updates, and removes packages.
  • Usage: apt install package-name
  • Options:
    • apt update: Updates package lists.
    • apt upgrade: Upgrades all packages.

yum (CentOS/RHEL)

  • Description: Manages packages in RPM-based distributions.
  • Usage: yum install package-name

dnf

  • Description: Modern package manager for RHEL/CentOS.
  • Usage: dnf install package-name

pacman (Arch Linux)

  • Description: Installs, removes, and updates Arch Linux packages.
  • Usage: pacman -S package-name

zypper (SUSE)

  • Description: Package management for SUSE-based systems.
  • Usage: zypper install package-name

snap

  • Description: Manages snap packages.
  • Usage: snap install package-name

flatpak

  • Description: Manages Flatpak applications.
  • Usage: flatpak install package-name

10. User Management

whoami

  • Description: Displays the current logged-in user.
  • Usage: whoami

passwd

  • Description: Changes the user password.
  • Usage: passwd

useradd

  • Description: Adds a new user.
  • Usage: useradd new_user

usermod

  • Description: Modifies user properties.
  • Usage: usermod -aG groupname username

id

  • Description: Displays user ID and group ID.
  • Usage: id username

groups

  • Description: Lists the groups a user belongs to.
  • Usage: groups username

deluser

  • Description: Deletes a user account.
  • Usage: deluser username

Leave a Comment