Master Essential Linux Commands: grep, ls, find, wc, and More
This guide provides a comprehensive overview of common Linux command‑line tools—including grep, ls, find, wc, cat, tail, head, du, which, whereis, sort, netstat, more, less, ps, tmux, ack and kill—detailing their basic syntax, useful options, and practical examples for both macOS and Debian environments.
Commands marked with (Mac) were tested on macOS, while the others were tested on Debian.
1. grep command
Text search command that supports regular expressions and can search one or multiple files. Basic format: grep [option] [regex] [path] -o show only the matching part of each line -c output only the count of matching lines -n display line numbers of matches -v display lines that do not match -i ignore case -R recursive search in directories -l list only matching file names -H show file name with each match -A NUM show NUM lines after each match -B NUM show NUM lines before each match -C NUM show NUM lines surrounding each match --color highlight matches
2. ls command
Most frequently used command to list files in a directory. Basic format: ls [option] -a list all files, including those starting with ‘.’ -h human‑readable sizes -l long format with permissions, owner, size, etc. -s display file size -t sort by modification time -S sort by size -r reverse order -L show symbolic link targets -R list directories recursively
3. find command
File‑search command that recursively searches directories for files matching given criteria. Basic format: find [path] [option] [expression] -name match file name -perm match permission bits -user match file owner -mtime +n files modified more than n days ago -ctime +n files changed more than n days ago -newer f1 !f2 files modified between f1 and f2 -size n files of size n blocks (1 block = 512 bytes) -depth process a directory’s contents before the directory itself -prune exclude a directory from the search -type filter by file type (b = block, d = directory, f = regular file)
4. wc command
Counts bytes, words, and lines in the input. Basic format: wc [option] [filename] -c count bytes -l count lines -m count characters -w count words
5. cat command
Concatenates and displays file contents. Basic format: cat [option] [filename] -n number all output lines -b number non‑blank lines only
6. tail command
Displays the last part of a file; can follow a growing file in real time. Basic format: tail [option] [filename] -n number show the last NUMBER lines (or start from line NUMBER with +) -f follow the file as it grows -k number start reading from the specified kilobyte offset Example: tail -n -5 catalina.out shows the last 5 lines.
7. head command
Displays the beginning of a file. Basic format: head [option] [filename] -n number show the first NUMBER lines (negative numbers exclude the last lines) -c number show the first NUMBER bytes Example: head -n 5 server.xml
8. du command
Shows disk usage of files and directories. Basic format: du [option] [name] -h human‑readable output --max-depth=number limit recursion depth -a display sizes for all files, not just directories Example: du -h displays sizes of all sub‑directories.
9. which and whereis
which searches the directories listed in $PATH for an executable; whereis searches a database for binaries, man pages, and source files. which -m search only manual pages which -b search only binaries
10. sort command
Sorts lines of text files. Basic format: sort [option] [filename] -u output unique lines only -n sort numerically -r reverse order -k start,end sort using the key from field START to END Example: sort -nk 2 -t - sort.txt sorts numerically on the second ‘‑’‑delimited field.
11. netstat command
Displays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships. Basic format: netstat [option] -a show all sockets -l show listening sockets only -n show numerical addresses -p show PID/program name -r display routing table -t show TCP connections -u show UDP connections -s display network statistics Example: netstat -anp shows all connections with PIDs.
12. more command
Displays file contents page by page and allows forward searching. Basic format: more [option] [filename] +n start displaying at line n -n set screen size to n lines +/pattern search forward for pattern -s squeeze multiple blank lines into one Common keys: Enter (next line), Ctrl+F (next screen), Ctrl+B (previous screen), Space (next screen), = (show line number), /pattern (search forward).
13. less command
Improved pager that allows both forward and backward navigation and searching without loading the whole file. Basic format: less [option] [filename] -N show line numbers -i ignore case in searches -s squeeze consecutive blank lines -m display percentage progress Search commands: /string forward, ?string backward, n repeat last search, Space (next page), d (half page), b (back page), y (back line), q (quit).
14. ps command
Displays a snapshot of current processes. Basic format: ps [option] -a show processes of all users -x show processes without a controlling terminal -u select processes by user name -f full‑format listing -j display job control information -e show all processes Examples: ps -ef (standard format), ps aux (user‑oriented format).
15. tmux command (Mac)
Terminal multiplexer that allows multiple panes, windows, and sessions within a single terminal. Basic format: tmux [option] tmux new -s sessionName create a new session tmux attach -t sessionName re‑attach to a session tmux kill-session -t sessionName terminate a session tmux ls list all sessions Common key bindings: Ctrl+b d detach, Ctrl+b c create new window, Ctrl+b w list windows, Ctrl+b <number> switch windows, Ctrl+b " split horizontally, Ctrl+b % split vertically.
16. ack command (Mac)
Search tool similar to grep but faster and with smarter defaults. Basic format: ack [option] [pattern] -w match whole words only --ignore-dir exclude specified directories Example: ack -w test searches for the whole word “test”.
17. kill command
Terminates processes by sending signals. Basic format: kill [params] [pid] -1 SIGHUP (terminal disconnect) -2 SIGINT (interrupt, same as Ctrl+C) -3 SIGQUIT (quit, same as Ctrl+\) -15 SIGTERM (default termination signal) -9 SIGKILL (force kill) -18 SIGCONT (continue) -19 SIGSTOP (stop, same as Ctrl+Z) Common usage: kill -9 1234 forcefully terminates process 1234.
Author: Huang Huan Source: http://sadwxqezc.github.io/HuangHuanBlog/linux
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
