To redirect the output of a command to a file in Bash, you can use the >
or >>
symbol.
Here are the steps to redirect the output:
ls
command to a file named output.txt
. The command would be: ls
.>
symbol after the command, followed by the filename. This symbol redirects the output and overwrites the file each time you run the command. The updated command would be: ls > output.txt
.>>
symbol instead of >
. The updated command would be: ls >> output.txt
.Note: If the file does not exist, it will be created. If it already exists, the >
symbol will overwrite the existing content, while the >>
symbol will append the new output to the end of the file.