This may not be the best way, but could you just do something like this?:
cat file1 > file2
cp /dev/null file1
The first command should write out all of the contents of file1 (assuming it's not a binary) to file2. The second command will just "zero" out file1 without removing it.
Why not just using the normal "cp" with the -p flag (to get the same permission bits and owner settings for the copy) and afterwards just rub out file1's contents?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.