Operations 18 min read

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 efficient system navigation and text processing.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Essential Linux Commands: grep, ls, find, wc, and More

This article presents a concise reference for frequently used Linux commands, explaining their purpose, basic syntax, key options, and example usages.

1. grep command

Searches text using regular expressions across one or multiple files.

Basic format

grep [option] [regex] [path]
-o

Show only the matching part of each line. -c Output the count of matching lines. -n Display line numbers of matches. -v Show lines that do not match. -i Case‑insensitive search. -R Recursively search directories. -l List only the names of matching files. -H Show file names with matches. -A NUM Show NUM lines after each match. -B NUM Show NUM lines before each match. -C NUM Show NUM lines around each match. --color Highlight matches.

Example: grep -lR a ./*.yml searches for "a" in all *.yml files under the current directory and lists only the matching file names.

2. ls command

Lists files and directories.

Basic format

ls [option]
-a

Include hidden files (those starting with a dot). -h Human‑readable sizes. -l Long format with permissions, owners, timestamps, etc. -s Show file sizes. -t Sort by modification time. -S Sort by size. -r Reverse order. -L Show symbolic link targets. -R Recursively list subdirectories.

3. find command

Recursively searches directories for files that meet specified criteria.

Basic format

find [path] [option] [expression]
-name

Match file name. -perm Match permission bits. -user Match file owner. -mtime -n +n Match files modified n days ago. -ctime -n +n Match files created n days ago. -newer f1 !f2 Files newer than f1 but older than 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 device, d = directory, f = regular file).

Example: find . -maxdepth 2 -size 3 limits the search depth to two levels and finds files of size three blocks.

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 (separated by whitespace).

5. cat command

Concatenates and displays file contents.

Basic format

cat [option] [filename]
-n

Number all output lines. -b Number non‑empty output lines.

6. tail command

Shows the last part of a file and can follow live updates.

Basic format

tail [option] [filename]
-n number

Number of lines to display (e.g., +5 start at line 5, -10 last 10 lines). -f Follow the file as it grows. -k number Start reading at the specified kilobyte offset.

Example: tail -n -5 catalina.out prints the last five 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 shows the first five lines of server.xml.

8. du command

Displays disk usage of files and directories.

Basic format

du [option] [name]
-h

Human‑readable output. --max-depth=number Limit recursion depth. -a Show sizes for all files, not just directories.

Example: du -h shows the size of each subdirectory in the current folder.

9. which and whereis commands

which

searches the directories listed in $PATH for an executable; whereis searches a database for binaries, source, and manual pages (faster but may be outdated). -m Search only manual pages. -b Search only binaries.

10. sort command

Sorts lines of text files.

Basic format

sort [option] [filename]
-u

Suppress duplicate lines. -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 by the second field using "-" as delimiter.

11. netstat command

Displays network connections, routing tables, and interface statistics.

Basic format

netstat [option]
-a

Show all sockets. -l Show listening sockets. -n Show numerical addresses. -p Show PID/program name. -r Display routing table. -t Show TCP connections. -u Show UDP connections. -s Show network statistics.

Example: netstat -anp lists all connections with PIDs.

12. more command

Pages through a file, displaying one screen at a time and supporting forward search.

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.

Example: more +/Deploy catalina.out finds the first occurrence of "Deploy" and shows the surrounding lines.

13. less command

Similar to more but allows both forward and backward navigation without loading the entire file.

Basic format

less [option] [filename]
-N

Show line numbers. -i Case‑insensitive search. -s Squeeze blank lines. -m Show percentage progress.

Search commands: /pattern forward, ?pattern backward, n repeat last search.

14. ps command

Reports a snapshot of current processes.

Basic format

ps [option]
-a

Show processes of all users. -x Show processes without a controlling terminal. -u Select by user name. -f Full‑format listing. -j Job format. -e Show every process.

Examples: ps -ef (standard full listing) and ps aux (BSD‑style listing).

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.

16. ack command (Mac)

Search tool similar to grep but optimized for programmers.

Basic format

ack [option] [pattern]
-w

Match whole words. --ignore-dir Exclude specified directories.

Example: ack -w test searches for the whole word "test".

17. kill command

Sends signals to terminate or control processes.

Basic format

kill [params] [pid]
-1

SIGHUP (terminal disconnect). -2 SIGINT (interrupt, same as Ctrl+C). -3 SIGQUIT (same as Ctrl+\). -15 SIGTERM (default termination signal). -9 SIGKILL (forceful termination). -18 SIGCONT (continue). -19 SIGSTOP (stop, same as Ctrl+Z).

Common usage: kill -9 1234 forcefully kills process 1234.

rwx

7

-wx

3

rw-

6

-w-

2

r-x

5

--x

1

r--

4

---

0

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Shellcommand-lineUnix toolssystem-administration
MaGe Linux Operations
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.