Quick Tip: Delete the Contents of a File without Removing and Recreating It
Do all this from the command line or terminal.
This will create a new file named t whose contents is the word "test":
$] echo "test" > t
more will display the contents of the file:
$] more t
test
Here's the new trick I learned. cat reads the contents of /dev/null (which contains nothing) and > writes this into t
$] cat /dev/null > t
Now t contains nothing:
$] more t
Get rid of it (don't do this to your logfile)
$] rm t
Another command :
$] > file.txt
$]echo > something.txt
$]echo "" > something.txt
for windows:
$]copy con > file.txt
$]copy nul > file.txt
This will create a new file named t whose contents is the word "test":
$] echo "test" > t
more will display the contents of the file:
$] more t
test
Here's the new trick I learned. cat reads the contents of /dev/null (which contains nothing) and > writes this into t
$] cat /dev/null > t
Now t contains nothing:
$] more t
Get rid of it (don't do this to your logfile)
$] rm t
Another command :
$] > file.txt
$]echo > something.txt
$]echo "" > something.txt
for windows:
$]copy con > file.txt
$]copy nul > file.txt
0 Comments:
Post a Comment
<< Home