Hi, this is Sandra Henry-Stocker, author of the “Unix as a Second Language” blog on NetworkWorld.
In today’s 2-minute Linux tip, we’re going to look at a command that you might never have heard of. It’s called logsave and it allows you to selectively add command output to a file. The syntax is simple. You type a command like:
$ logsave mylog who
And the output from the command you’ve entered (who in this case) gets added to the file you’ve selected (mylog in this case) along with two timestamps that show when the command started and completed.
With no additional command options, logsave overwrites any prior file content. If you want to append to the file instead of overwriting it, use the -a option:
$ logsave -a mylog uptime
If we look at the file at this point, we’ll see the output from both commands along with the timestamps.
$ cat mylog
If you want to selectively add the output of commands that you are running to a file as you work, you might consider setting up an alias like this to help ensure that you don’t overwrite previous content by forgetting the -a option:
$ alias sv=’logsave -a mylog’
After setting up this alias, you can simply precede any command whose output you want to save with “sv” and its output will be appended to the specified file.
$ sv find . -type f -empty
$ sv echo "that's all, folks"
The results of these commands to 1) find empty files and 2) wave goodbye are now in our mylog file.
$ tail mylog
Closing: That’s your 2-minute Linux tip for today. If you liked this video, please hit the like and share buttons. For more Linux tips, be sure to follow us on Facebook, YouTube and NetworkWorld.com.