sorting a file without using temporary files sorting a file without using temporary files bash bash

sorting a file without using temporary files


Use

sort -o foo foo

From the man page:

-o OUTPUT-FILE' Write output to OUTPUT-FILE instead of standard output. If OUTPUT-FILE is one of the input files,sort' copies it to a temporary file before sorting and writing the output to OUTPUT-FILE.

sort foo > foo means writing output to the standard output which is redirected to the output file. Before redirecting, > will truncate/overwrite the output file if one is exist. Since both the input and output files are same, you will lose the input file information.