SpyTM Discussion Board

How to Truncate a file without deleting the file  

  RSS

Anonymous
 Anonymous
(@Anonymous)
Guest
Joined: 49 years  ago
Posts: 0
22/04/2016 9:02 pm  

I want to write a shell script in which the file will be truncated if there is any unknown data found. Any option to truncate the UNIX file or variable instead of deleting the original file?


ReplyQuote
Anonymous
 Anonymous
(@Anonymous)
Guest
Joined: 49 years  ago
Posts: 0
23/06/2016 2:18 am  

Try this:

cp /dev/null filename

/dev/null is an empty file which is present in all the UNIX and LINUX machines.
Copying this file will overwrite the content of the original file and make it empty.

cat /dev/null > filename

This command also does the same job.


ReplyQuote

Recent Articles

Share: