grep

中級
1/8
user@linux:~/workspace$
grep "ERROR" logs/app.log

Explanation

Displays all lines containing "ERROR" in the logs/app.log file. grep is case-sensitive by default.

Options

-iCase-insensitive search
-nDisplay line numbers
-rSearch directories recursively
-cCount matching lines
-vShow lines that don't match
-C NShow N lines before and after match
-RSearch directories recursively, also following symbolic links
-lShow only filenames of matches
-wMatch whole words only
-A NShow N lines after match
-B NShow N lines before match
1[INFO] 2026-01-13 09:00:00 Application started
2[DEBUG] 2026-01-13 09:00:05 Loading configuration from config/app.conf
3[INFO] 2026-01-13 09:00:10 Database connection established
4[DEBUG] 2026-01-13 09:00:15 Cache initialized (Redis)
5[INFO] 2026-01-13 09:00:20 Server listening on port 3000
6[WARN] 2026-01-13 09:15:30 High memory usage detected: 85%
7[ERROR] 2026-01-13 09:30:45 Failed to process payment: timeout
8[INFO] 2026-01-13 09:31:00 Payment retry successful
9[DEBUG] 2026-01-13 09:45:00 Processed 1523 requests in last hour
10[INFO] 2026-01-13 10:00:00 Daily backup completed