Truncating files in directory
I truncated the files in one of the directory with .log extension.
I wrote a script something like this: filecount=`ls -1 *.log 2>/dev/null | wc -l` if [ $filecount -gt 0 ] then for i in `ls -1 *.log` do echo > $i done fi Here, when it all the files perfectly except the last file. For the last file, instead of truncating it , it creates a new files with same name appended with ? at the end of the file name. How can overcome this problem. is there something wrong with my script. |
I can not reproduce it, but people should use 'find' for finding files instead of trying to list them. With 'find' you also don't need the "filecount" check and it doesn't break with spaces (IFS) like 'ls' does. You could also check the ABS about the difference between "for" and "while" loops. So. How about using 'find /some/path -maxdepth 1 -type f -iname \*.log -print0|xargs -0 -iX echo truncate 'X'' instead?
|
All times are GMT -5. The time now is 10:22 AM. |