Jump to content

Recommended Posts

  • Administrators
Posted

To clear / truncate / empty file in linux u can use below command from bash:

 

cat /dev/null >| filename

 

Does anyone know any other commands to achieve the same thing in linux?

Posted

echo "" > filename

 

:> filename

 

>filename

 

rm filename && touch filename

 

cat /dev/null > filename

 

truncate -s0 filename

  • Like 1
Posted (edited)

try below

 

cp /dev/null filename

 

while the next one below will give you a visually empty file but the size of the file would still be 1 since

""

is a character #13 or #10 which is invincible to human eyes. :P

echo "" > filename

 

also, the below code should be executed under the actual ownership of the file, so it doesnt change file ownership and access.

rm filename && touch filename

 

If you are root and going to do the last command with file(s) owned by postfix or named, the last command above is critical and may create another issue for you I think so.

Edited by PiNoY

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.