linux_pipes_flashcards
(15 cards)
What is a pipe (|
) in Linux?
A pipe is used to take the output of one command and pass it as input to another command.
What is the syntax for using a pipe in Linux?
Syntax: command1 | command2
- This passes the output of command1
as input to command2
.
What is STDOUT
in Linux?
STDOUT
(Standard Output) is the default stream where command output is displayed, usually on the screen.
What is STDIN
in Linux?
STDIN
(Standard Input) is the input stream that a command receives, typically from the keyboard or another command using a pipe.
Where is the pipe (|
) key located on a US keyboard?
The pipe key is usually above the Enter
or Return
key and is shared with the backslash (\
).
How do you filter the output of a command using pipes?
Use grep
. Example: dmesg | grep sda5
filters the system logs to show only lines containing ‘sda5’.
How do you view long command output one page at a time?
Use less
. Example: dmesg | less
to scroll through output one page at a time.
How do you count the number of lines, words, or characters in a command’s output?
Use wc
. Example: ls -l | wc -l
counts the number of files in a directory.
How do you sort command output using pipes?
Use sort
. Example: cat file.txt | sort
sorts file contents alphabetically.
How can you remove duplicate lines from command output?
Use uniq
. Example: cat file.txt | sort | uniq
sorts and removes duplicates.
What does the xargs
command do?
xargs
takes piped input and executes a command multiple times with each entry.
How can you create multiple directories from a list using pipes?
Use xargs
with mkdir
. Example: cat directories.txt | xargs mkdir
creates directories listed in directories.txt
.
Why do some commands not work with pipes directly?
Some older commands do not support direct piping. Using xargs
or proper redirection can help format input correctly.
How can you count how many times a word appears in a file using pipes?
Example: cat file.txt | grep 'word' | wc -l
counts the number of lines where ‘word’ appears.
How can you find the most used words in a file?
Example: cat file.txt | tr ' ' '\n' | sort | uniq -c | sort -nr
counts and displays most common words.