Jump to content

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

truncate - empty(clear) file in linux

- - - - - linux truncate debian

  • Please log in to reply
2 replies to this topic

#1
daredevil

daredevil

    Profiler

  • Administrators
  • 21,838 posts
7,262
Guardian of the faith
  • Xfire:hellreturn
  • Admin:21
  • Server:None
  • Alias:hellreturn
Contributor
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!

#2
Krauersaut

Krauersaut

    L9: Master

  • Regular User
  • 2,228 posts
983
Is a bearer of wisdom
  • Server:None
Contributor
echo "" > filename

:> filename

>filename

rm filename && touch filename

cat /dev/null > filename

truncate -s0 filename


#3
PiNoY

PiNoY

    Your Number One Super Noob Bone Breaking Samurai

  • Leader
  • 3,626 posts
1,446
Honorable bastion of truth
  • Xfire:verpinoy
  • Admin:20
  • Server:Jay3
  • Alias:father
  • Steam ID:verpinoy
  • T-M:ET: 7-4
Contributor
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 - 08: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