Was working with log files and wanted a quick way to empty them and recreate them. rm and touch would do it, but found something simpler:
CODE:
-
cat /dev/null > filename
As simple as that!
Nirav Mehta on life, technology and future
September 17th, 2007 | GNU/Linux
Was working with log files and wanted a quick way to empty them and recreate them. rm and touch would do it, but found something simpler:
As simple as that!
8 comments ↓
Try
echo -n > file

try
echo > filename
Try
> filename
Yes, I get shortest command prize
Wow.
I’m in awe. I’ll have to remember these next time i am working with log files and such!
:> is the POSIX way, iirc. The dummy placeholder : makes it work on some shells where a plain > doesn’t.
cat has supercow power!
cat /dev/cdrom > foo.iso to create iso from cdrom
you can also use
cat > [the filename u want to clear]
Press Ctrl D..
You’re done….
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.
Leave a Comment