What is the fastest / most elegant way to read out a file and then write the content to that same file?
On Linux, this is not always the same as 'touching' a file, e.g. if the file represents some hardware device.
One possibility that worked for me is echo $(cat $file) > $file
but I wondered if this is best practice.
echo $(cat $file) >$file
. The lack of quotes means your newlines get turned to spaces and your globs get expanded.touch
didn't work in this case. My solution works fine so far but I don't know much about the specifics.