Unix/Linux : How to pipe/save output of a command to file?
Problem :
You need to capture/pipe or save the output of a command execution in Unix/Linux to a file. How to do that?
Solutions :
Use the greater than sign >
to save the output to a file.
For example :
cat /var/log > /tmp/varlog.log
ls /dir > dir.txt
**NOTE : >
will overwrite or create new file. >>
will append to existing file.
you can also use the logsave
command to capture the output. However, the logsave
command is only available on Linux platform.
For example :
logsave [options] /tmp/varlog.log cat /var/log
Save of the logsave
options are :
-a This option will cause the output to be appended to logfile, instead of replacing its current contents.
-s This option will cause logsave to skip writing to the log file text which is bracketed with a control-A (ASCII 001 or Start of Header)
and control-B (ASCII 002 or Start of Text). This allows progress bar information to be visible to the user on the console,
while not being written to the log file.
-v This option will make logsave to be more verbose in its output to the user.
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+14.1k Golang : How to login and logout with JWT example
+12.7k Golang : Fix cannot use buffer (type bytes.Buffer) as type io.Writer(Write method has pointer receiver) error
+9.8k Golang : Removes punctuation or defined delimiter from the user's input
+5.9k Golang : How to call function inside template with template.FuncMap
+3.9k JQuery : Calling a function inside Jquery(document) block
+31.3k Golang : Regular Expression for alphanumeric and underscore
+15.6k Golang : Capture stdout of a child process and act according to the result
+7.7k Golang : Find network service name from given port and protocol
+8.6k Golang : Populate slice with sequential integers example
+8.7k Golang : Sort and reverse sort a slice of integers
+5.4k Golang : Break string into a slice of characters example
+28.9k Golang : Generate random string