
Common Linux Commands Cheat Sheet
1. ls – List Directory Contents
Syntax:ls [options] [path]
Usage:
Displays the files and directories in the specified directory (current directory by default).
Common Switches:
-l: Long listing format (permissions, owner, size).-a: Include hidden files (those starting with a dot).-lh: Human-readable file sizes (e.g., KB, MB).-R: List directories recursively.
2. cd – Change Directory
Syntax:cd [path]
Usage:
Changes the current directory to the specified directory.
Common Switches:
..: Go up one directory level.-: Go to the previous directory.~: Go to the home directory.
3. pwd – Print Working Directory
Syntax:pwd
Usage:
Displays the current directory’s full path.
4. mkdir – Make Directory
Syntax:mkdir [options] [directory_name]
Usage:
Creates a new directory.
Common Switches:
-p: Create parent directories if they don’t exist.-v: Show the directories being created.
5. rm – Remove Files or Directories
Syntax:rm [options] [file_name]
Usage:
Removes files or directories.
Common Switches:
-r: Remove directories and their contents recursively.-f: Force remove files (ignore nonexistent files and do not prompt).-i: Prompt before every removal.
6. cp – Copy Files and Directories
Syntax:cp [options] [source] [destination]
Usage:
Copies files or directories.
Common Switches:
-r: Copy directories recursively.-i: Prompt before overwriting files.-u: Copy only when the source file is newer than the destination file or if the destination file is missing.
7. mv – Move or Rename Files
Syntax:mv [options] [source] [destination]
Usage:
Moves or renames files or directories.
Common Switches:
-i: Prompt before overwriting files.-u: Move only when the source file is newer than the destination file or if the destination file is missing.-v: Display the actions being performed.
8. touch – Create Empty File or Update Timestamp
Syntax:touch [file_name]
Usage:
Creates an empty file or updates the timestamp of an existing file.
Common Switches:
-c: Do not create any files if they do not exist.-t: Set a specific timestamp.
9. cat – Concatenate and Display Files
Syntax:cat [file_name]
Usage:
Displays the contents of a file.
Common Switches:
-n: Number all output lines.-b: Number non-blank lines.-E: Display a dollar sign ($) at the end of each line.
10. echo – Display Text or Variables
Syntax:echo [options] [string]
Usage:
Prints text or variables to the terminal.
Common Switches:
-n: Do not output the trailing newline.-e: Enable interpretation of backslash escapes (e.g.,\nfor newline,\tfor tab).-E: Disable backslash escapes.
11. man – Display Manual Pages
Syntax:man [command]
Usage:
Displays the manual page for a command, showing detailed usage.
12. find – Search for Files
Syntax:find [path] [expression]
Usage:
Searches for files and directories based on criteria.
Common Switches:
-name [pattern]: Search for files by name.-type [d|f]: Search for directories (d) or files (f).-exec [command]: Execute a command on the found files.-size [size]: Find files of a specific size.
13. grep – Search Text Using Patterns
Syntax:grep [options] [pattern] [file]
Usage:
Searches for a pattern within files.
Common Switches:
-i: Case-insensitive search.-r: Search recursively in directories.-v: Invert the match (show lines that do not match the pattern).-l: List only filenames that match the pattern.-n: Show line numbers with matching lines.
14. ps – View Process Status
Syntax:ps [options]
Usage:
Shows information about running processes.
Common Switches:
-e: Show all processes.-f: Show full format listing.-u [user]: Show processes belonging to a specific user.
15. top – Monitor System Processes
Syntax:top
Usage:
Displays a real-time view of system processes and resource usage.
Common Switches:
-d [seconds]: Set the delay between updates.-u [user]: Show processes for a specific user.
16. df – Display Disk Space Usage
Syntax:df [options] [path]
Usage:
Shows the disk space usage of the file system.
Common Switches:
-h: Human-readable format (e.g., KB, MB).-T: Show file system type.-a: Include pseudo, duplicate, and inaccessible file systems.
17. du – Disk Usage
Syntax:du [options] [path]
Usage:
Shows disk usage for directories.
Common Switches:
-h: Human-readable format (e.g., KB, MB).-s: Show only the total size of the specified directory.-a: Show disk usage for all files and directories.
18. chmod – Change File Permissions
Syntax:chmod [options] [permissions] [file]
Usage:
Changes file or directory permissions.
Common Switches:
-R: Change permissions recursively.-v: Verbosely show permissions being changed.
19. chown – Change File Owner and Group
Syntax:chown [options] [user]:[group] [file]
Usage:
Changes the owner and group of a file or directory.
Common Switches:
-R: Change ownership recursively.-v: Verbosely show ownership changes.
20. sudo – Execute Command as Superuser
Syntax:sudo [command]
Usage:
Executes a command with superuser (root) privileges.
Common Switches:
-u [user]: Run the command as a different user.-i: Start a shell with root privileges.-s: Run the shell specified in the environment variableSHELL.
21. apt – Package Management (Debian-based Systems)
Syntax:apt [options] [command]
Usage:
Manages packages on Debian-based systems.
Common Switches:
update: Update package list from repositories.install [package]: Install a package.remove [package]: Remove a package.upgrade: Upgrade all installed packages.search [package]: Search for a package.
22. yum – Package Management (RHEL/CentOS)
Syntax:yum [options] [command]
Usage:
Manages packages on RHEL/CentOS-based systems.
Common Switches:
search [package]: Search for a package.
install [package]: Install a package.
remove [package]: Remove a package.
update: Update all installed packages.
