Hi ,
I tried to remove around 7,000 log files under a directory by using
rm *.log
but failed with error message "too long argument list" . Is there any way to slove it ?
thanks .
Hi ,
I tried to remove around 7,000 log files under a directory by using
rm *.log
but failed with error message "too long argument list" . Is there any way to slove it ?
thanks .
Try
find . -name '*.log' -delete
Note that this will also delete files in subdirectories. To avoid that, add -maxdepth 1
before the -delete
I think the reason why this problem is with rm/ls and not with find, is because:
rm *.log
appends all the files matching "*.log"
to rm as argument
so the system complains long argument list.
So, i think simply:
ls | grep ".*\.log" | xargs rm
also does the job.
In case of find, the directory is searched first and files are matched with the pattern and those satisfying it are deleted.
Addon : Using xargs, if there's space within the file name reference the below,
find ./ -iname 'someglob*' -print0 | xargs -0 rm -rf