| Shell - Clear Text File need a shell script to clear the contents of a text file |
cookiemonster

msg:4155334 | 7:46 pm on Jun 19, 2010 (gmt 0) | Hi, I need a simple script that can clear the contents of a text (.txt) file without actually DELETING the file. Is there any way this can be done? Also, is there any way this can be done to clear the contents of all files with the name "hits.txt" in a given directory? Thanks!
|
lammert

msg:4155586 | 3:13 pm on Jun 20, 2010 (gmt 0) | The easiest way to clear one file is to copy the null device to the text file: /bin/cp /dev/null /somedirectory/hits.txt For all files in the /start/directory tree with the name hits.txt, the following script might work: /usr/bin/find /start/directory -type f -name hits.txt -exec /bin/cp /dev/null {} \;
|
cookiemonster

msg:4155592 | 3:29 pm on Jun 20, 2010 (gmt 0) | Thanks lammert, both commands worked perfectly!
|
|
|