6 ms·
And prefer redirection to cat. whatever < file.txt not cat file.txt | whatever Also, there is no need for - or z on GNU tar in t or x modes: t
by trapperkeeper74 9y ago
And prefer redirection to cat.
whatever < file.txt
not
cat file.txt | whatever
Also, there is no need for - or z on GNU tar in t or x modes:
tar tf whatever.tgz
tar tf whatever.tar.bz2
tar tf whatever.txz
...
tar xf whatever.tar.gz
tar xf whatever.tar.Z
...
all work just fine
- TorKlingberg 9y agoI know whatever < file.txt is slightly more efficient, but there is value is keeping things going left to right with pipes in between. It makes it easy to insert a grep or sort, or swap out a part.
- veddan 9y ago<file.txt grep foo | sort
- joombaga 9y agoOh cool. Didn't know this was possible.
- BenjiWiebe 9y agoOk, if that actually works, that's amazing. Wow.
- vram22 9y agoIt works because of the general principle that I mentioned here: https://news.ycombinator.com/item?id=15249370 https://news.ycombinator.com/item?id=15249370 The shell (not the command) is the one expanding those metacharacters, so (within limits), in: cmd < file or < file cmd where you put that piece (< file) on the line does not matter, because the actual command cmd never sees the redirection at all - it is done [1] by the time the command starts. The cmd command will only see the command line arguments (other than redirections) and options (arguments that start with a dash). Even expansion of $ and other sigils (unless quoted) happens before the command starts. [1] I.e. the shell and kernel set up the standard input of the command to be connected to the file opened for reading (in the case of < file).
- traviscj 9y agoI prefer cat because > vs < is an easy typo to make but one clobbers the file. Happy to pay the performance penalty as insurance against that.
- vram22 9y agoYou can use the bash setting called noclobber to prevent such accidental deletion. https://en.wikipedia.org/wiki/Clobbering https://en.wikipedia.org/wiki/Clobbering