Essential Linux Command Reference for System Tasks

1. Information Maintenance Commands

wc (Word Count)

Counts lines, words, and characters in a file.

  • wc file.txt — Show lines, words, and characters
  • wc -l file.txt — Count only lines
  • wc -w file.txt — Count only words
  • wc -c file.txt — Count only characters

clear (Clear Screen)

Clears the terminal screen.

clear

cal (Calendar)

Displays a calendar of the current or specified month/year.

  • cal — Show current month’s calendar
  • cal 2025 — Show calendar for the year 2025
  • cal 03 2025 — Show calendar for March 2025

who (Who is Logged In)

Lists users currently logged into the system.

  • who — Show logged-in users
  • whoami — Show current user

date (Show Date & Time)

Displays the current date and time.

  • date — Show current date and time
  • date "+%Y-%m-%d" — Show only the date in YYYY-MM-DD format

pwd (Print Working Directory)

Displays the full path of the current directory.

pwd

File Management Commands

cat (Concatenate and Display File Contents)

  • cat file.txt # Show file contents
  • cat file1.txt file2.txt > merged.txt # Merge files

cp (Copy Files)

  • cp source.txt destination.txt # Copy file
  • cp -r source_dir/ destination_dir/ # Copy directory

rm (Remove/Delete Files)

  • rm file.txt # Delete file
  • rm -r directory/ # Delete directory and contents

mv (Move/Rename Files)

  • mv oldname.txt newname.txt # Rename file
  • mv file.txt /path/to/destination/ # Move file

cmp (Compare Two Files Byte-by-Byte)

cmp file1.txt file2.txt # Check if files are identical

comm (Find Common and Unique Lines in Two Sorted Files)

comm file1.txt file2.txt

diff (Show Differences Between Two Files)

diff file1.txt file2.txt

find (Search for Files and Directories)

  • find /home -name "file.txt" # Find file by name
  • find / -type d -name "test" # Find directory named ‘test’

grep (Search for Patterns in a File)

  • grep "keyword" file.txt # Search for “keyword” in file.txt
  • grep -i "word" file.txt # Case-insensitive search
  • grep -r "pattern" /dir/ # Recursive search in directory

awk (Pattern Matching and Processing)

  • awk '{print $1}' file.txt # Print first column from file
  • awk '/pattern/' file.txt # Print lines matching ‘pattern’

3. Directory Management Commands

cd (Change Directory)

  • cd /home/user # Change to /home/user directory
  • cd .. # Move one level up

mkdir (Create a New Directory)

mkdir newdir

rmdir (Remove an Empty Directory)

rmdir emptydir

ls (List Directory Contents)

  • ls # List files and directories
  • ls -l # List with details
  • ls -a # Show hidden files

4. Process Control Commands

ps (Show Running Processes)

  • ps # Show active processes
  • ps aux # Show all processes with details

kill (Terminate a Process)

  • kill 1234 # Kill process with PID 1234
  • kill -9 1234 # Force kill process

sleep (Pause Execution)

sleep 10 # Pause execution for 10 seconds

5. Communication Commands

Input-Output Redirection

  • command > file.txt # Redirect output to a file
  • command >> file.txt # Append output to a file
  • command < input.txt # Read input from a file

Pipe (|)

  • ls -l | grep ".txt" # List only .txt files
  • ps aux | grep firefox # Find Firefox process

6. Protection Management Commands

chmod (Change File Permissions)

  • chmod 777 file.txt # Give all permissions (rwxrwxrwx)
  • chmod 644 file.txt # Read/write for owner, read-only for others
  • chmod +x script.sh # Make script executable

chown (Change File Ownership)

  • chown user file.txt # Change owner
  • chown user:group file.txt # Change owner and group

chgrp (Change Group Ownership)

chgrp groupname file.txt