linux_pipes_flashcards

(15 cards)

1
Q

What is a pipe (|) in Linux?

A

A pipe is used to take the output of one command and pass it as input to another command.

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

What is the syntax for using a pipe in Linux?

A

Syntax: command1 | command2 - This passes the output of command1 as input to command2.

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

What is STDOUT in Linux?

A

STDOUT (Standard Output) is the default stream where command output is displayed, usually on the screen.

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

What is STDIN in Linux?

A

STDIN (Standard Input) is the input stream that a command receives, typically from the keyboard or another command using a pipe.

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

Where is the pipe (|) key located on a US keyboard?

A

The pipe key is usually above the Enter or Return key and is shared with the backslash (\).

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

How do you filter the output of a command using pipes?

A

Use grep. Example: dmesg | grep sda5 filters the system logs to show only lines containing ‘sda5’.

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

How do you view long command output one page at a time?

A

Use less. Example: dmesg | less to scroll through output one page at a time.

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

How do you count the number of lines, words, or characters in a command’s output?

A

Use wc. Example: ls -l | wc -l counts the number of files in a directory.

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

How do you sort command output using pipes?

A

Use sort. Example: cat file.txt | sort sorts file contents alphabetically.

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

How can you remove duplicate lines from command output?

A

Use uniq. Example: cat file.txt | sort | uniq sorts and removes duplicates.

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

What does the xargs command do?

A

xargs takes piped input and executes a command multiple times with each entry.

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

How can you create multiple directories from a list using pipes?

A

Use xargs with mkdir. Example: cat directories.txt | xargs mkdir creates directories listed in directories.txt.

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

Why do some commands not work with pipes directly?

A

Some older commands do not support direct piping. Using xargs or proper redirection can help format input correctly.

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

How can you count how many times a word appears in a file using pipes?

A

Example: cat file.txt | grep 'word' | wc -l counts the number of lines where ‘word’ appears.

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

How can you find the most used words in a file?

A

Example: cat file.txt | tr ' ' '\n' | sort | uniq -c | sort -nr counts and displays most common words.

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