How to print each new line of command output to the file?

 To print each new line of command output to a file, you can use the `tee` command in combination with a pipeline. Here's how you can do it:


```bash

your_command | tee -a output_file.txt

```


Replace `your_command` with the actual command you want to run, and `output_file.txt` with the name of the file where you want to save the output. The `-a` option in `tee` appends the output to the file, so if the file exists, the output will be added to it without overwriting its contents. If the file doesn't exist, it will be created.


For example, if you want to save the output of a command called `my_command` to a file named `output.log`, you would run:


```bash

my_command | tee -a output.log

```


This will both display the output on your terminal and append it to the `output.log` file.

Comments

Popular posts from this blog

bad character U+002D '-' in my helm template

GitLab pipeline stopped working with invalid yaml error

How do I add a printer in OpenSUSE which is being shared by a CUPS print server?