Jump to content

  • Log in with Facebook Log in with Twitter Log In with Google Sign In
  • Create Account

truncate - empty(clear) file in linux

- - - - - linux truncate debian

  • Please log in to reply
2 replies to this topic




  • Administrators
  • 25,824 posts
Guardian of the faith
  • Xbox Live:hellreturn
  • EvolveHQ:hellreturn
  • Admin:21
  • Server:None
  • Alias:hellreturn
  • T-M:2-2
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?

Click here to login or here to register to remove this ad, it's free!



    L9: Master

  • Regular User
  • 2,228 posts
I am just really nice
  • Server:None
echo "" > filename

:> filename


rm filename && touch filename

cat /dev/null > filename

truncate -s0 filename



    Your Number One Super Noob Bone Breaking Samurai

  • Honored Veteran
  • 3,710 posts
Name known to all
  • Admin:20
  • Server:Jay3
  • Alias:father
  • Steam ID:verpinoy
  • T-M:ET: 8-6
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, 30 May 2012 - 11:01 AM.

Also tagged with one or more of these keywords: linux, truncate, debian

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users