Appending Rather Than Clobbering Output

Problem

Each time you redirect your output, it creates that output file anew. What if you want to redirect output a second (or third, or …) time, and don’t want to clobber the previous output?

Solution

The double greater-than sign (>>) is a bash redirector that means append the output:

$ ls > /tmp/ls.out
$ cd ../elsewhere
$ ls >> /tmp/ls.out
$ cd ../anotherdir
$ ls >> /tmp.ls.out
$

Discussion

The first line includes a redirect that removes the file if it exists and starts with a clean (empty) file, filling it with the output from the ls command.

The second and third invocations of ls use the double greater than sign (>>) to indicate appending to, rather than replacing, the output file.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.164.34