This post is part of my Today I learned series in which I share all my learnings regarding web development.
Today I came across this tweet by Safia Abdalla. It showed that you can use the
cat command to quickly add content to a file (
cat - >> foo.txt). The way it works is that you can directly write to
stdin until you hit
So I opened the manual for the
cat command and wanted to see what else is in there. One sentence suprised me though.
If file is a single dash (`-') or absent, cat reads from the standard input.
You can make the snippet even shorter! 😲
$ cat - >> foo.txt # is the same as $ cat >> bar.txt
I also discovered that you can use
stdin right in between files and concat them (you have to use
^C doesn't work then). 🎉
$ cat 1.txt - 3.txt > all.txt