Comments on: How to empty a file without deleting and recreating it? http://www.mehtanirav.com/2007/09/17/how-to-empty-a-file-without-deleting-and-recreating-it/ Nirav Mehta on life, technology and future Sun, 20 Jan 2013 14:48:56 +0000 hourly 1 http://wordpress.org/?v=3.5.1 By: Sinan E. http://www.mehtanirav.com/2007/09/17/how-to-empty-a-file-without-deleting-and-recreating-it/comment-page-1/#comment-137165 Sinan E. Wed, 11 Apr 2012 06:22:11 +0000 http://www.mehtanirav.com/2007/09/17/how-to-empty-a-file-without-deleting-and-recreating-it/#comment-137165 > filename

Saved my life. Thanks.

]]>
By: VaibhaV Sharma http://www.mehtanirav.com/2007/09/17/how-to-empty-a-file-without-deleting-and-recreating-it/comment-page-1/#comment-93005 VaibhaV Sharma Tue, 18 Sep 2007 18:27:50 +0000 http://www.mehtanirav.com/2007/09/17/how-to-empty-a-file-without-deleting-and-recreating-it/#comment-93005 Ah, about the echo > filename, it will work on any shell as compared to the “> filename” but some apps don’t like the one newline character that echo leaves in the file. So edit the file with vi, dd the first line, save and you are done.

]]>
By: aamod http://www.mehtanirav.com/2007/09/17/how-to-empty-a-file-without-deleting-and-recreating-it/comment-page-1/#comment-92984 aamod Tue, 18 Sep 2007 15:31:48 +0000 http://www.mehtanirav.com/2007/09/17/how-to-empty-a-file-without-deleting-and-recreating-it/#comment-92984 you can also use

cat > [the filename u want to clear]

Press Ctrl D..
You’re done….

]]>
By: Kartik Mistry http://www.mehtanirav.com/2007/09/17/how-to-empty-a-file-without-deleting-and-recreating-it/comment-page-1/#comment-92967 Kartik Mistry Tue, 18 Sep 2007 12:43:10 +0000 http://www.mehtanirav.com/2007/09/17/how-to-empty-a-file-without-deleting-and-recreating-it/#comment-92967 cat has supercow power!

cat /dev/cdrom > foo.iso to create iso from cdrom ;)

]]>
By: alephnull http://www.mehtanirav.com/2007/09/17/how-to-empty-a-file-without-deleting-and-recreating-it/comment-page-1/#comment-92954 alephnull Tue, 18 Sep 2007 10:59:15 +0000 http://www.mehtanirav.com/2007/09/17/how-to-empty-a-file-without-deleting-and-recreating-it/#comment-92954 :> is the POSIX way, iirc. The dummy placeholder : makes it work on some shells where a plain > doesn’t.

]]>
By: James Urquhart http://www.mehtanirav.com/2007/09/17/how-to-empty-a-file-without-deleting-and-recreating-it/comment-page-1/#comment-92937 James Urquhart Tue, 18 Sep 2007 09:50:32 +0000 http://www.mehtanirav.com/2007/09/17/how-to-empty-a-file-without-deleting-and-recreating-it/#comment-92937 Wow.

I’m in awe. I’ll have to remember these next time i am working with log files and such! :)

]]>
By: Tejas Dinkar http://www.mehtanirav.com/2007/09/17/how-to-empty-a-file-without-deleting-and-recreating-it/comment-page-1/#comment-92880 Tejas Dinkar Tue, 18 Sep 2007 02:49:16 +0000 http://www.mehtanirav.com/2007/09/17/how-to-empty-a-file-without-deleting-and-recreating-it/#comment-92880 Try

> filename

Yes, I get shortest command prize :D

]]>
By: VaibhaV Sharma http://www.mehtanirav.com/2007/09/17/how-to-empty-a-file-without-deleting-and-recreating-it/comment-page-1/#comment-92859 VaibhaV Sharma Mon, 17 Sep 2007 23:47:44 +0000 http://www.mehtanirav.com/2007/09/17/how-to-empty-a-file-without-deleting-and-recreating-it/#comment-92859 try

echo > filename

]]>
By: Atul http://www.mehtanirav.com/2007/09/17/how-to-empty-a-file-without-deleting-and-recreating-it/comment-page-1/#comment-92824 Atul Mon, 17 Sep 2007 17:44:17 +0000 http://www.mehtanirav.com/2007/09/17/how-to-empty-a-file-without-deleting-and-recreating-it/#comment-92824 Try

echo -n > file
:)

]]>