wc command
Counts lines, words, and characters in text.
What is the wc command syntax?
wc [options] file
Example of using wc to count lines in syslog?
wc -l /var/log/syslog
What is wc commonly used for?
Monitoring file sizes and contents for diagnostics and troubleshooting.
sort command
Organizes lines of text based on specified criteria.
What is the syntax for the sort command?
sort [options] file
Example of sorting /etc/passwd by UIDs in descending order?
sort -t: -k3,3 -n -r /etc/passwd
What does -t do in sort?
Specifies a field delimiter.
What does -k do in sort?
Indicates which column to sort by.
What does -n do in sort?
Performs a numeric sort.
What does -r do in sort?
Reverses the order of the sort.
Why is sort useful for system administrators?
Helps identify anomalies or security risks by organizing data logically.
What does the uniq command do?
Filters out or reports adjacent repeated lines in sorted data
What is the syntax for uniq?
uniq [options] [input [output]]
Why is uniq often used with sort?
Because uniq only detects adjacent duplicates, and sorting groups duplicates together.
Example: Counting repeated lines in auth.log?
sort /var/log/auth.log | uniq -c
What does -c do in uniq?
Counts and displays how often each line appears.
Why is uniq useful?
Helps analyze logs, summarize data, and detect repeating patterns.
What does the xargs command do?
Constructs and executes command lines from standard input.
What is the syntax for xargs?
xargs [options] command
Example of using xargs to copy log files?
find /home/logs -type f -name “*.log” | xargs -I {} -n 1 -p -t cp {} /backup/logs/
What does -I {} do in xargs?
Replaces {} with the input item (e.g., file name).
What does -n 1 do in xargs?
Processes one input per command.
What does -p do in xargs?
Prompts for confirmation before executing each command.