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
+9.8k Golang : Detect number of active displays and the display's resolution
+7.9k Golang : Trim everything onward after a word
+16.5k Golang : Send email and SMTP configuration example
+8.8k Golang : Random integer with rand.Seed() within a given range
+14.8k Golang : Find commonalities in two slices or arrays example
+7.8k Golang : Example of how to detect which type of script a word belongs to
+36.4k Golang : How to split or chunking a file to smaller pieces?
+25.4k Golang : Convert long hexadecimal with strconv.ParseUint example
+28.1k Golang : Move file to another directory
+6.2k Golang : Grab news article text and use NLP to get each paragraph's sentences
+7.7k Golang : Error reading timestamp with GORM or SQL driver
+11.8k Golang : Verify Linux user password again before executing a program example