I raised eyebrows recently when I was working with someone and we needed to create a file and instead of starting an editor I did: cat > filename ... Ctrl-D
Why not touch or echo? No reason for an editor or cat
PSA about abuse of cat(1) command. Don't abuse cats
21–30 of 62 posts
Re: PSA about abuse of cat(1) command. Don't abuse cats
#22Don't do this: cat file | wc -l => wc -l head -n 5 file cat file | awk '{print $1}' => awk '{print $1}' file cat file | sort => sort file Do this instead: cat file | wc -l => The front-cat abuse is all about the order. The effective solution needs to keep the relative order of arguments.
Or just use cat and spend your brainpower on interesting, useful, and/or worthwhile topics. It boggles my mind that anyone cares about this.
Re: PSA about abuse of cat(1) command. Don't abuse cats
#23Re: PSA about abuse of cat(1) command. Don't abuse cats
#24Earlier quoted context omitted.
Or just use cat and spend your brainpower on interesting, useful, and/or worthwhile topics. It boggles my mind that anyone cares about this.
Probably, but knowing that redirection operators can be freely moved within normal arguments [EDIT: thank ButlerianJihad for pursuing me to make this more accurate] is useful.
cat file > /dev/null 2>&1
work as intended.Re: PSA about abuse of cat(1) command. Don't abuse cats
#25Earlier quoted context omitted.
Probably, but knowing that redirection operators can be freely moved within normal arguments [EDIT: thank ButlerianJihad for pursuing me to make this more accurate] is useful.
They are actually not “order-independent”, and their L-R parsing/processing is why constructs such as cat file > /dev/null 2>&1 work as intended.
2>&1 >/dev/null cat file
appears to yield the same output. So i wonder where the not "order-independent" chimes in.Re: PSA about abuse of cat(1) command. Don't abuse cats
#26if this wanton abuse of cat(1) doesn't stop, we're on track to run out of PIDs by 2031! Just because Unix makes it cheap and easy to fork doesn't mean you have to! (who gives even a single shit, my god)
Re: PSA about abuse of cat(1) command. Don't abuse cats
#27Earlier quoted context omitted.
They are actually not “order-independent”, and their L-R parsing/processing is why constructs such as cat file > /dev/null 2>&1 work as intended.
funny enough, 2>&1 >/dev/null cat file appears to yield the same output. So i wonder where the not "order-independent" chimes in.
It does not yield the "same output", and here is why: if you cause your command to actually produce output on stderr (fd 2) it will appear as terminal output, because you have actually succeeded in "redirecting" stderr to wherever stdout (fd 1) was pointing initially.
Re: PSA about abuse of cat(1) command. Don't abuse cats
#28Personally, when I'm exploring, I build a command line iteratively. Cat the file to see the content, pipe to grep to get the lines I want, sed/awk/cut/etc to finagle from there.