0
0
Linux CLIscripting~5 mins

stdin redirection (<) in Linux CLI - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the stdin redirection operator (<) do in Linux command line?
It takes input for a command from a file instead of the keyboard. The command reads data from the file as if it was typed by the user.
Click to reveal answer
beginner
How would you use stdin redirection to provide a file named input.txt as input to the sort command?
You write: sort < input.txt. This tells sort to read its input from input.txt instead of waiting for keyboard input.
Click to reveal answer
intermediate
True or False: Using command < file is the same as cat file | command.
True. Both send the contents of the file as input to the command, but < is simpler and more efficient.
Click to reveal answer
beginner
What happens if you use stdin redirection with a file that does not exist?
The shell will show an error like bash: file: No such file or directory and the command will not run.
Click to reveal answer
beginner
Why is stdin redirection useful in scripting and automation?
It lets scripts read input from files automatically without user typing. This helps run commands on saved data quickly and repeatably.
Click to reveal answer
What does the operator < do in a Linux command?
ARedirects output to a file
BRedirects input from a file to a command
CPipes output from one command to another
DRuns a command in the background
Which command uses stdin redirection correctly?
Agrep 'hello' < file.txt
Bgrep 'hello' > file.txt
Cgrep 'hello' | file.txt
Dgrep 'hello' & file.txt
What error occurs if the file used with < does not exist?
AFile is created automatically
BCommand runs with empty input
CCommand ignores the file and runs normally
DShell shows 'No such file or directory' error
How is < different from a pipe (|)?
A< is for background jobs; | is for input
B< sends output; | sends input
C< sends input from a file; | sends output from a command
D< and | do the same thing
Why prefer < over cat file | command?
A< is simpler and uses less resources
Bcat is faster
CThey are exactly the same in all ways
Dcat is more secure
Explain how stdin redirection (<) works and give a simple example.
Think about how a command reads data without typing.
You got /3 concepts.
    Describe a situation where stdin redirection helps automate a task.
    Imagine you want to process many files quickly.
    You got /3 concepts.