I'm trying to delete image cache files older then 100 days via command

find /mnt/data/cache/*.jpg -maxdepth 0 -mtime +100 -type f -ls -delete

but the thing is /mnt/data/cache/ contain large amount of files and i'm getting as error

bash: /usr/bin/find: Argument list too long

there is no subdirectories in /mnt/data/cache/. All files in that /mnt/data/cache/ folder and standard -maxdepth 0 solution is not helping

So is there any way to do find by some portions or offset limits ? or is there some alternative command by which i can delete files in directory older then 100 days ??

1 Answer 1

find /mnt/data/cache/*.jpg ...

will expand to

find /mnt/data/cache/1.jpg /mnt/data/cache/2.jpg /mnt/data/cache/3.jpg ...

If you have too many file, this cause error you've seen.

If there is no subdir, you can skip -maxdepth 0 and -type f

what you want is

find /mnt/data/cache/ -mtime +100 -name \*.jpg -ls -delete

a final word, if you append > /dev/null, just drop -ls

  • Yes working thank you
    – Armen
    Jul 6, 2020 at 6:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .