commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
Ever need to erase the contents of a file and start over from scratch? This easy command allows you to do so. Be warned! This will immediately erase all the contents of your file and start you over from scratch (i.e. your file will be at 0 bytes, like if you touch a file).
There are 6 alternatives - vote for the best!
The downside of output redirection is that you need permissions. So something like
won't play nicely w/ sudo. You'd need to do something like
bash -c '> file'
instead, you could go w/
sudo truncate -s0 file
Immediately make a file empty. This even works if the file is still being written to. Great for cleaning up huge log files!
If you can do better, submit your command here.
You must be signed in to comment.