-1

I'm trying to delete files inside a certain folder but it's throwing an error:

rm -rf /usr/html/sched/downloads/*

-bash: /bin/rm: Argument list too long

I searched online and found this solution but I'm afraid to try it being a production server and I don't know how to put the path correctly:

find . -name '*' | xargs rm -v

How can I delete thousands of files within the /downloads director? FYI, there's no sub-directory.

Elaine Byene
  • 3,868
  • 12
  • 50
  • 96
  • Does this answer your question? [Argument list too long error for rm, cp, mv commands](https://stackoverflow.com/questions/11289551/argument-list-too-long-error-for-rm-cp-mv-commands) – Benjamin W. Oct 01 '21 at 14:57
  • Will this command work? `find . -name "/usr/html/sched/downloads/*" -delete` – Elaine Byene Oct 01 '21 at 15:41
  • You would probably rather do `find /usr/html/sched/downloads -type f -delete`; you can replace `-delete` with `-print` first so see if the files are the right ones. Notice that `-delete` is a) a GNU find extension and b) can only delete files, not directories. – Benjamin W. Oct 01 '21 at 16:40
  • Could you post this as an answer? I got it working. Thank you :) – Elaine Byene Oct 01 '21 at 17:22
  • It's an exact duplicate of what I posted, can you accept the duplicate instead? – Benjamin W. Oct 01 '21 at 17:53

1 Answers1

0

I think here you can check how you can handle it because for a large scale of files you will need to do it by a specific quantity by milliseconds.

find ./cache -mtime +0.5 -print0 | xargs -0 rm -f

Faster way to delete a large number of files [duplicate]

Jose Lora
  • 1,392
  • 4
  • 12
  • 18
  • Will this work: `find rm -rf /usr/html/sched/downloads/* -mtime +0.5 -print0 | xargs -0 rm -f` – Elaine Byene Oct 01 '21 at 15:42
  • Link only answers are not allowed on SO. [answer] Either form your own answer or delete this altogether. – Rob Oct 02 '21 at 09:35