Recall & Review
beginner
What is a file descriptor in bash scripting?
A file descriptor is a number that represents an open file or input/output resource in bash. Common ones are 0 for standard input, 1 for standard output, and 2 for standard error.
Click to reveal answer
beginner
How do you redirect standard output to a file in bash?
Use the > symbol followed by the filename. For example,
echo "Hello" > file.txt sends the output to file.txt instead of the screen.Click to reveal answer
intermediate
What does the command
2>&1 do in bash?It redirects standard error (file descriptor 2) to the same place as standard output (file descriptor 1). This way, both outputs go to the same destination.
Click to reveal answer
beginner
Explain the difference between
> and >> in bash redirection.> overwrites the file with new output, while >> appends the output to the end of the file without deleting existing content.Click to reveal answer
intermediate
How can you redirect only standard error to a file, leaving standard output unchanged?
Use
2> filename. For example, command 2> error.log sends error messages to error.log but shows normal output on the screen.Click to reveal answer
Which file descriptor number represents standard input in bash?
✗ Incorrect
Standard input is always file descriptor 0.
What does the command
ls > files.txt do?✗ Incorrect
The > symbol redirects output to the file, overwriting it.
How do you append output to a file instead of overwriting it?
✗ Incorrect
The >> operator appends output to the file.
What does
command 2>&1 do?✗ Incorrect
It sends standard error (2) to the same place as standard output (1).
How to redirect only error messages to a file named error.log?
✗ Incorrect
2> redirects only standard error to the file.
Describe what file descriptors 0, 1, and 2 represent in bash and how you can redirect each.
Think about where data comes from and goes to in commands.
You got /6 concepts.
Explain how to combine standard output and standard error into one file using redirection.
Remember the order matters in redirection.
You got /3 concepts.