Sort and Count Flashcards

(29 cards)

1
Q

wc command

A

Counts lines, words, and characters in text.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the wc command syntax?

A

wc [options] file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Example of using wc to count lines in syslog?

A

wc -l /var/log/syslog

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is wc commonly used for?

A

Monitoring file sizes and contents for diagnostics and troubleshooting.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

sort command

A

Organizes lines of text based on specified criteria.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the syntax for the sort command?

A

sort [options] file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Example of sorting /etc/passwd by UIDs in descending order?

A

sort -t: -k3,3 -n -r /etc/passwd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does -t do in sort?

A

Specifies a field delimiter.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does -k do in sort?

A

Indicates which column to sort by.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does -n do in sort?

A

Performs a numeric sort.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does -r do in sort?

A

Reverses the order of the sort.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Why is sort useful for system administrators?

A

Helps identify anomalies or security risks by organizing data logically.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does the uniq command do?

A

Filters out or reports adjacent repeated lines in sorted data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the syntax for uniq?

A

uniq [options] [input [output]]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Why is uniq often used with sort?

A

Because uniq only detects adjacent duplicates, and sorting groups duplicates together.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Example: Counting repeated lines in auth.log?

A

sort /var/log/auth.log | uniq -c

17
Q

What does -c do in uniq?

A

Counts and displays how often each line appears.

18
Q

Why is uniq useful?

A

Helps analyze logs, summarize data, and detect repeating patterns.

19
Q

What does the xargs command do?

A

Constructs and executes command lines from standard input.

20
Q

What is the syntax for xargs?

A

xargs [options] command

21
Q

Example of using xargs to copy log files?

A

find /home/logs -type f -name “*.log” | xargs -I {} -n 1 -p -t cp {} /backup/logs/

22
Q

What does -I {} do in xargs?

A

Replaces {} with the input item (e.g., file name).

23
Q

What does -n 1 do in xargs?

A

Processes one input per command.

24
Q

What does -p do in xargs?

A

Prompts for confirmation before executing each command.

25
What does -t do in xargs?
Prints the command before executing it.
26
What does -L do in xargs?
Sets the maximum number of input lines per execution.
27
What does -E do in xargs?
Defines a termination string that stops input processing.
28
What does -s do in xargs?
Sets the maximum size of the command line.
29
What is xargs typically used for?
Batch processing, automating file management, and system maintenance.