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[/code]
As simple as that!
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[/code]
As simple as that!
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.
> filename
Saved my life. Thanks.