-
Website
http://www.tech-recipes.com/ -
Original page
http://www.tech-recipes.com/rx/2993/how_to_empty_or_clear_the_contents_of_an_existing_unix_file/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
davak
83 comments · 1 points
-
Web Design
3 comments · 1 points
-
danishbacker
9 comments · 1 points
-
flexinfo
11 comments · 1 points
-
Tonychelle
4 comments · 1 points
-
-
Popular Threads
-
PowerPoint 2010: How To Convert a Presentation to Video (WMV format)
5 days ago · 1 comment
-
Windows Live Mail: Automatically Spell Check All Email Before Sending
1 week ago · 2 comments
-
Firefox: How to Make Google Reader the Default RSS Reader for Subscribing to Feeds
1 week ago · 1 comment
-
Facebook: How To Get Only Status Updates on Your FB Home Page
4 weeks ago · 4 comments
-
Outlook 2010: Download Images Automatically
1 week ago · 1 comment
-
PowerPoint 2010: How To Convert a Presentation to Video (WMV format)
touchcommand may also be used to create a new file that is empty.
echo "" > fileCheers,
Philip
These tips are important, as they do not close the file handle; useful for logs.
And just as a curiosity both methods also work on the OS X.
cat /dev/null >/Filaname
If the file is in use this will affectively zero out the contents, the only time I found this to be a problem is with Java programming. It appears the java program reads everything in to memroy and then writes to cache. If you hit the timing right, you can zero out the file, and all of a sound the full contents will be back. Like I said, I have only seen this in a java program writing to the disk. In all other cases, like zero'ing mail boxes, or large log files, it works welll.
touch only creates an empty file if none are present, echo "" adds the unix delimiter LF.
Later+
Mike
It will save you a t and a >.
it does empty the file, but you need to Ctrl+c after...
echo " " > blah.txt
But whatever works will do :)
for i in 'ls';
do
echo "" >$i;
done