Empty (truncate) th...
 

Empty (truncate) the file without deleting the file  


Alan
Posts: 35
 Alan
(@alan)
Eminent Member
Joined: 3 months ago

I want to delete only the content of the log file in UNIX without deleting the complete file. Instead of deleting and recreating the file, is there any command to truncate the file content alone?

1 Reply
admin
Posts: 93
Admin
(@mjv119gmail-com)
Member
Joined: 5 years ago

I would recommend to delete and recreate a fresh file since truncating the file is not a good idea. If you want to truncate then try this,

cat /dev/null > file_name

/dev/null is an empty file which is present in all the machines. Here I used cat command to amend that empty file to the filename. So the content of the file will get truncated. cheers…

Reply

Leave a reply


 
Preview 0 Revisions Saved
Share: