Let’s say you’ve got a terminal open and you want to sort the contents of a file before you email it to a friend. The file can contain anything and it could be of any length, it doesn’t matter. What do you do?
The obvious answer is to use sort
. Sorting the file is as easy as sort myfile
– except it doesn’t actually sort the file, it sorts the *contents* of the file and dumps them to the command line (via stdout
). So how do you sort the file “in-place,” so-to-speak? Again, the obvious answer would be sort myfile > myfile
,1 redirecting the output of the sort command back to the file you want to ultimately send sorted.
Don’t do this! ↩