To write the output of a command or script into a file in Linux, you can use the >
operator. The >
operator redirects the output of a command or script to a file, overwriting the file if it already exists.
Here's an example of using the >
operator to write the output of a command into a file:
ls -l > file.txt
This command will execute the ls -l
command, which lists the files in the current directory, and write the output to the file file.txt
. If the file file.txt
already exists, it will be overwritten with the output of the ls
command.
You can also use the >>
operator to append the output of a command or script to a file, rather than overwriting it.
Here's an example of using the >>
operator to append the output of a command to a file:
ls -l >> file.txt
This command will execute the ls -l
command, and append the output to the end of the file file.txt
. If the file file.txt
does not exist, it will be created.