Essential Linux Command Reference Guide

Operating System Overview

An operating system serves as the bridge between hardware and software, managing device resources while providing interfaces for users and applications.

Classification

Ctaegory Examples
Desktop OS Windows, Linux, macOS
Server OS Linux, Windows Server
Embedded OS Linux
Mobile OS iOS, Android

Directory Structure

/           - Root directory (top-level)
/home       - User home directories
/root       - Superuser home directory
/bin        - Essential binary executables

Command Syntax

command [options] [arguments]
command --help     # Display help information
man command        # Show manual pages

Core File Operations

Navigation Commands

pwd                 # Display current working directory
cd ~                # Return to home directory
cd /                # Jump to root directory
cd -                # Switch to previous directory
cd /path/to/dir     # Absolute path navigation
cd subdir           # Relative path navigation

Arrow keys cycle through command history. Press Ctrl+C to terminate a running command.

Directory Listing

ls                  # List files
ls -a               # Include hidden files
ls -l               # Show detailed information
ls -lh              # Human-readable sizes
ls -lah             # Combined options
ls = ll             # Shortcut for ls -l
ls a*               # Files starting with 'a'
ls a?               # Files matching 'a' plus single character
ls {abc}d           # Match 'ad', 'bd', or 'cd'

Permission format: drwx rwx rwx owner group

  • First triplet: owner permissions
  • Second triplet: group permissions
  • Third triplet: others permissions

Directory Management

mkdir -p /path/to/new/dir    # Create with parent directories
mkdir project/{male,female}   # Create multiple subdirectories
mkdir .hidden                 # Create hidden directory

Every directory contains . (current) and .. (parenet) entries.

File Creation

touch filename.txt    # Create empty file
gedit filename        # Create and edit with GUI

Deletion

rm file1 file2              # Remove files
rm -r directory             # Remove directory recursively
rm *                        # Remove all files in directory
rm -f file                  # Force removal without confirmation

Copying

cp source.txt destination.txt
cp -r source_dir target_dir

Moving and Renaming

mv oldname.txt newname.txt    # Rename
mv file.txt /path/to/dir/      # Move to directory
mv directory /target/location/ # Move directory

Input/Output Redirection

ls > output.txt          # Redirect output to file (overwrite)
ls >> output.txt         # Append output to file
cat file1.txt file2.txt > combined.txt

Large File Viewing

more filename.txt
  • Space - Next page
  • b - Previous page
  • q - Quit

Piping

command1 | command2    # Pass output of command1 as input to command2
ls -l | more           # Paginate directory listing

Searching

grep - Pattern Matching

grep "pattern" file               # Search within file
grep -n "hello" . -r              # Recursive search with line numbers
grep -n "^hello" file             # Lines starting with 'hello'
grep -n "hello$" file             # Lines ending with 'hello'
grep -n "h." file                 # Lines containing 'h' followed by any character

find - File Lookup

grep -n "pattern" . -r             # Find in current directory recursively
find /home -name "report.txt"     # Find file by exact name
find /home -name "*.txt"          # Find files with extension

Archiving and Compression

Creating Archives

tar cf archive.tar file1.txt file2.txt    # Create archive
tar tf archive.tar                         # List archive contents

Extracting Archives

tar xf archive.tar                         # Extract to current directory
tar xf archive.tar -C /target/dir/         # Extract to specific directory

Combined Compression

tar czf archive.tar.gz *.txt              # Compress with gzip
tar zxf archive.tar.gz -C target_dir       # Decompress and extract

System Administration

which command           # Locate command binary path
su                      # Switch to root user
su username             # Switch to specific user
passwd user            # Change user password
who                     # Show logged-in users

Terminal types:

  • pts/X - Pseudo terminal (remote/ssh)
  • ttyX - Physical terminal

Session Management

exit                   # Logout current session
pkill -kill -t tty1    # Force terminate specific terminal session
reboot                 # Restart system
shutdown               # Shutdown (requires root)

File Permissions

chmod Syntax

chmod [who][operator][permission] file

Who:

  • u - Owner
  • g - Group
  • o - Others
  • a - All

Operator: + add, - remove, = set

Permissions: r read (4), w write (2), x execute (1)

chmod u+r,g-w,o=x test.txt    # Modify specific permissions
chmod 777 test.txt            # Full permissions for all

Vim Editor Commands

Cursor Movement

Command Action
h Move left
j Move down
k Move up
l Move right
M Jump to middle line
L Jump to last line
G Go to line number
gg Go to file beginning
G Go to file end
w Next word
b Previous word
{ Previous paragraph
} Next paragraph

Scrolling

Command Action
Ctrl+d Scroll down half page
Ctrl+u Scroll up half page
Ctrl+f Scroll down full page
Ctrl+b Scroll up full page

Deletion

Command Action
x Delete character under cursor
X Delete character before cursor
dd Delete current line
ndd Delete n lines
D Delete from cursor to line end
d0 Delete from line start to cursor
dw Delete current word

Undo and Repeat

Command Action
u Undo last change
Ctrl+r Redo
. Repeat last operation

Text Indentation

Command Action
>> Indent line right
<< Indent line left

Copy and Paste

Command Action
yy Copy current line
nyy Copy n lines
p Paste below cursor

Visual Mode

Command Action
v Character selection
V Line selection

Visual mode supports d, y, >>, << for operations on selected blocks.

Search and Replace

Command Action
/pattern Search forward
n Next match
N Previous match
r Replace single character
R Enter replace mode

Tags: Linux Command Line file operations Vim editor System Administration

Posted on Mon, 15 Jun 2026 18:03:00 +0000 by katierosy