Quiz Entry - updated: 2026.06.20
How do you redirect standard output (stdout) to a file in Linux?
Use > (or the explicit 1>) — ls > files.txt sends normal output to the file instead of the screen.
ls > files.txt # stdout into files.txt
ls 1> files.txt # identical — the 1 is just explicit
The bare > defaults to FD 1 (stdout), so > file and 1> file mean exactly the same thing. You almost never write the 1; it only becomes useful for clarity when stderr is also in play.
Watch out — > truncates:
- If the file exists, it is wiped the moment the command starts (even before any output is produced), then rewritten from scratch.
- If it doesn't exist, it's created.
- Nothing appears on screen — the output went into the file.
This "truncate first" behaviour bites people: sort file > file destroys file (the shell empties it before sort ever reads it). To append instead of overwrite, use >>.
Tip: Want to add to a file, not replace it? That's >>, covered separately.