Essential Linux Command Cheat Sheet: Paths, Files, Processes, and More
A comprehensive guide covering common Linux shell commands, including path symbols, directory navigation, file manipulation, process management, permission changes, searching, and environment handling, presented as concise questions and answers for quick reference by developers and system administrators.
Question 1: Path symbols and directory navigation
Absolute path: e.g., /etc/init.d. Current directory: ./. Parent directory: ../. Home directory: ~/. Change directory command: cd.
Question 2: Viewing processes, exiting, and current path
View current processes: ps. Exit the shell: exit. Show current working directory: pwd.
Question 3: Clearing screen, exiting commands, sleeping, user ID, and help
Clear screen: clear. Abort current command: Ctrl+C. Suspend a job (sleep): Ctrl+Z then resume with fg. Show current user ID: id. View command help: man <command> or <command> --help or info <command>.
Question 4: ls functionality and options
lslists directories and files. Common options: -a (show all files, including hidden) and -l (long format with permissions, size, etc.).
Question 5: Creating symbolic and hard links
Symbolic link: ln -s <source> <link>. Hard link: ln <source> <link>.
Question 6: Creating directories, files, and copying files
Create directory: mkdir <dir>. Create file: touch <file> or use editors like vi. Copy file: cp <source> <dest>. Change file permissions: chmod with symbolic (e.g., chmod u+x file) or numeric modes (e.g., chmod 751 file).
Source: https://www.cnblogs.com/hystj/p/8552757.html
Question 8: Viewing file contents
vi <file>– edit and view cat <file> – display entire file more <file> – paginate forward less <file> – paginate forward and backward tail <file> – show last lines (optional -n) head <file> – show first lines
Question 9: Writing files and echoing strings with spaces
Write file: use vi or redirect output. Echo a string with spaces: echo hello world.
Question 10: Terminal device and null device
Terminal device file: /dev/tty. Null (black hole) device: /dev/null.
Question 11: Moving and renaming files
Move or rename: mv <source> <dest>.
Question 12: Copying directories and prompting
Copy directories recursively: cp -r <src_dir> <dest_dir>. Add prompt with -i option (e.g., cp -ri).
Question 13: Deleting files and directories
Delete file: rm <file>. Delete directory and its contents: rm -r <dir>. Remove empty directory: rmdir <dir>.
Question 14: Shell wildcard characters
?matches a single character. * matches zero or more characters. [charset] matches any single character in the set, e.g., [a-z] or [abABC].
Question 15: Counting lines, words, and bytes
Use wc: -l lines, -w words, -c bytes.
Question 16: grep usage
Search text with regular expressions. Ignore case with -i. Show lines not matching with -v. Example: grep pattern filename or grep -v pattern filename.
Question 17: Process states in Linux
Common states: Uninterruptible (D), Running (R), Sleeping (S), Stopped/Traced (T), Zombie (Z), etc. Symbols shown by ps correspond to these states.
Question 18: Running a command in the background
Append & to the command, e.g., command &.
Question 19: Listing all processes with ps
System‑V style: ps -ef. BSD style: ps -aux. Filter by PID: ps -ef | grep <pid>.
Question 20: Viewing background jobs
List jobs: jobs -l.
Question 21: Bringing jobs to foreground/background
Foreground: fg %<job>. Resume stopped job in background: bg %<job>.
Question 22: Terminating processes
Terminate: kill [-s SIGNAL] <pid> or kill -9 <pid> for forceful kill.
Question 23: Listing all supported signals
Show signals: kill -l.
Question 24: Searching for files
General search: find <path> -name <pattern>. Locate binary: whereis <name>. Quick name search: locate <name>.
Question 25: Wildcard characters (repeated)
Same as Question 14.
Question 26: Viewing command history
Show history: history.
Question 27: Checking disk usage
Show filesystem usage: df -hl.
Question 28: Checking network connectivity
Use netstat (or ss on newer systems).
Question 29: Displaying IP addresses and interfaces
Use ifconfig (or ip addr on newer systems).
Question 30: Viewing environment variables
List all: env. Show specific: echo $HOME or env | grep VAR.
Question 31: Customizing the shell prompt
Set PS1 with escape sequences: \u (user), \h (host), \W (basename of cwd), \w (full cwd, ~ for home), \$ (prompt symbol), \d (date), \t (24‑hour time), \T (12‑hour time), etc.
Question 32: Finding executable files
Search with whereis (binary, source, manual) or which (first executable in $PATH).
Question 33: Creating command aliases
Define alias: alias la='ls -a'.
Question 34: Difference between du and df
dureports disk usage of files/directories (user‑level). df reports filesystem‑level space allocation, including metadata.
Question 35: awk basics
Pattern‑action syntax: awk '{pattern + action}' file. Example: cat /etc/passwd | awk -F ':' '{print $1"\t"$7}' prints username and shell.
Question 36: Binding macros or keys in Bash
Use bind to assign a key sequence to a command, e.g., bind '"\e[24~":"date"'. Obtain key sequences with Ctrl+V or showkey -a.
Question 37: Listing the directory stack
Show stack: dirs. Manipulate with pushd and popd.
Question 38: Removing all running processes without reboot
Detach all jobs: disown -r.
Question 39: Bash hash command
Displays the internal hash table of command paths and usage counts.
Question 40: Bash arithmetic
Use built‑in let for integer arithmetic, e.g., let c=a+b.
Question 41: Paging through large files
Pipe to more or less: cat file | more or cat file | less.
Question 42: Data dictionary ownership (Oracle context)
Owned by the SYS user (system‑created).
Question 43: Getting a command’s summary
Use whatis <command> to display a brief description.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
