Essential Linux Command Cheat Sheet: Master Files, Processes, and Shell Basics
This comprehensive guide covers essential Linux commands for navigating directories, managing files, controlling processes, setting permissions, using search utilities, customizing the shell, and performing common administrative tasks, providing clear examples and syntax for each operation.
Question 1: How are absolute paths, current directory, parent directory, and home directory represented, and what command changes directories?
Answer: Absolute path example: /etc/init.d. Current and parent directories: ./ and ../. Home directory: ~/. Change directory command: cd.
Question 2: How to view current processes, exit the shell, and display the current path?
Answer: View processes: ps. Exit: exit. Show current path: pwd.
Question 3: How to clear the screen, abort a command, suspend a process, view user ID, and get help for a command?
Answer: Clear screen: clear. Abort command: Ctrl+C. Suspend process: Ctrl+Z (resume with fg). Show user ID: id. Get command help: man adduser, adduser --help, or info adduser.
Question 4: What does the ls command do and which options are common?
Answer: ls lists directory contents. Common options: -a (show all files) and -l (detailed list).
Question 5: How to create symbolic and hard links?
Answer: Symbolic link: ln -s slink source. Hard link: ln link source.
Question 6: Commands for creating directories, creating files, copying files, and changing file permissions?
Answer: Create directory: mkdir. Create file: touch (or vi). Copy file: cp. Change permissions: chmod (e.g., chmod u+x file, chmod 751 file, chmod -R u+r directory).
Question 8: Commands to view file contents?
Answer: vi filename, cat filename, more filename, less filename, tail filename, head filename.
Question 9: How to write to a file and echo a string with spaces?
Answer: Write file: vi. Echo with spaces: echo hello world.
Question 10: Which files represent the terminal and the null device?
Answer: Terminal: /dev/tty. Null device: /dev/null.
Question 11: Commands to move and rename files?
Answer: Move/rename: mv.
Question 12: Command to copy files and directories, with prompts?
Answer: Copy files: cp. Copy directories recursively: cp -r. (Prompt option not specified.)
Question 13: Commands to delete files, directories, and empty directories?
Answer: Delete files: rm. Delete recursively: rm -r. Remove empty directory: rmdir.
Question 14: Common Linux wildcard characters and their meanings?
Answer: ? matches a single character. * matches any number of characters. [charset] matches any single character in the set (e.g., [a-z], [abABC]).
Question 15: Command to count lines, words, and bytes?
Answer: wc with options -l (lines), -w (words), -c (bytes).
Question 16: What is grep used for and how to ignore case or find non-matching lines?
Answer: grep searches text using regular expressions. Use -i to ignore case, and -v to select non-matching lines (e.g., grep -i pattern file, grep -v pattern file).
Question 17: Linux process states and their symbols in ps output?
Answer: Uninterruptible (D), Running (R), Sleeping (S), Stopped/Traced (T), Zombie (Z), Swapped (W, obsolete), Dead (X).
Question 18: How to run a command in the background?
Answer: Append & to the command (no space required).
Question 19: How to list all processes and filter by PID?
Answer: List all: ps -ef (System V) or ps -aux (BSD). Filter: ps -ef | grep pid.
Question 20: Command to view background jobs?
Answer: jobs -l.
Question 21: Commands to bring a background job to the foreground or resume a stopped job?
Answer: Foreground: fg. Resume in background: bg.
Question 22: Command to terminate a process with options?
Answer: kill (e.g., kill -9 pid or kill -s SIGNAL pid).
Question 23: How to list all supported signals?
Answer: kill -l.
Question 24: Commands to search for files?
Answer: find <directory> <conditions> <actions>. Also whereis and locate for faster searches.
Question 25: How to see who is logged in and which terminal they are using?
Answer: Current terminal: who am i. All logged-in users: who.
Question 26: Command to view command history?
Answer: history.
Question 27: Commands to check disk usage and free space?
Answer: df -hl shows filesystem size, used, available, and mount points.
Question 28: Command to test network connectivity?
Answer: netstat.
Question 29: Command to display IP address and interface information?
Answer: ifconfig.
Question 30: Command to view environment variables?
Answer: Show all: env. Show specific: env $HOME.
Question 31: How to customize the Bash prompt?
Answer: Use escape sequences such as \u (user), \h (hostname), \W (current directory), \w (full path), \$ (prompt symbol), etc., in the PS1 variable.
Question 32: How does the shell locate executable files and how to modify the search path?
Answer: whereis searches for binaries, sources, and manuals with options like -b, -m, -s. The which command searches the PATH for the first matching executable.
Question 33: How to find the location of an executable?
Answer: Use which for executables; whereis for binaries, manuals, and source files.
Question 34: How to create an alias for a command?
Answer: alias la='ls -a'.
Question 35: Difference between du and df?
Answer: du reports disk usage of files and directories (user‑level). df reports filesystem‑level statistics, including metadata.
Question 36: Overview of awk usage.
Answer: awk '{pattern + action}' {filenames}. Example: cat /etc/passwd | awk -F ':' '{print $1"\t"$7}' prints username and shell.
Question 37: How to bind a macro or key sequence in Bash?
Answer: Use the bind command, e.g., bind '"\e[24~":"date"'. Obtain key sequences with Ctrl+V or showkey -a.
Question 38: How to list all commands supported by the system?
Answer: compgen -c prints all available commands.
Question 39: How to display the current directory stack?
Answer: dirs (managed with pushd and popd).
Question 40: How to detach all running processes without rebooting?
Answer: disown -r removes all jobs from the shell’s job table.
Question 41: What does the Bash hash command do?
Answer: It maintains a hash table of command paths, showing how many times each command has been executed.
Question 42: Which Bash built‑in performs arithmetic?
Answer: let evaluates integer expressions.
Question 43: How to view a large file page by page?
Answer: Pipe cat filename to more (e.g., cat file_name.txt | more).
Question 44: Which user owns the data dictionary?
Answer: The SYS user (system‑created).
Question 45: How to get a brief description of an unknown command?
Answer: Use whatis, e.g., whatis zcat.
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.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
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.
