unable to delete large number of files at a time

$  sudo -u jboss rm -rf  System*
-bash: /usr/bin/sudo: Argument list too long
$ ls -l | wc -l
$ ls -l | trace.log | wc -l
$ ls -l | grep SystemOut.log* | wc -l
-bash: /bin/grep: Argument list too long

There are around 5000 SystemOut.log.2010****  files under /opt/jboss/logs, i was not able to delete using the above command.

Please provide valid command or better way of deleting large number of files at a time.
wasmanIT AnalystAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Do this:


for file in $files
sudo rm -rf file
try opening a root shell with
sudo bash

Open in new window

and then just
rm -rf SystemOut.log.2010*

Open in new window

sudo ls -1 SystemOut.log.2010* | xargs rm -rf

"-1" is the digit "1" not the letter "l" !

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

OK, better with sudo at the end:

ls -1 SystemOut.log.2010* | xargs sudo -u jboss rm -rf
basically , the easiest way would be to get a longer example of random files you want to delete eg "SystemOut.log.040411" just for argument sake sys tem file for 4th april 2011. now to delete all of april log "rm SystemOut.log.04*" just go through manually until you've deleted enough to do the larger command of "SystemOut.log*"

store files in a variable, like farzani's suggestion:

If it doesn't work, you can try :

Then you delete all with :
rm -f $files

No need to loop.

Duhhh, just realized your problem is too long list of files. Go for a loop then ! You can still use my message for the listing of the files in the 'files' var...



for file in $files
sudo rm -rf file
sudo find /opt/jboss/logs/System* -type f -exec /bin/rm -f {} \;
Best way is:

sudo -u jboss find /opt/jboss/logs -name "System*" | xargs rm -f

Open in new window

Perhaps you could also try the Thunar file manager.
wasmanIT AnalystAuthor Commented:
Interestingly none of them worked for 5000 file, since it's a production server i couldn't take much chances. But i am closing this ticket

Thanks a lot for helping me
What do you mean "none of them worked"?
indeed , i've actually used my method a couple of times, slow , but gets the job done.
wasmanIT AnalystAuthor Commented:

They are like in this format, they are around 5000 files with different date stamp, but file name starts with UNHARVESTED
-rw-r--r--  1 kwdjn jbb   20971449 Apr 11 03:50 UNHARVESTED.trace_11.04.11_03.50.00.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb   20970332 Apr 11 03:52 UNHARVESTED.trace_11.04.11_03.52.40.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb   20971508 Apr 11 03:55 UNHARVESTED.trace_11.04.11_03.55.19.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb   20971519 Apr 11 03:57 UNHARVESTED.trace_11.04.11_03.57.59.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb   20971417 Apr 11 04:00 UNHARVESTED.trace_11.04.11_04.00.39.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb   20971441 Apr 11 04:03 UNHARVESTED.trace_11.04.11_04.03.18.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb   20971458 Apr 11 04:05 UNHARVESTED.trace_11.04.11_04.05.55.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb   20971472 Apr 11 04:08 UNHARVESTED.trace_11.04.11_04.08.35.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb   20969796 Apr 11 04:11 UNHARVESTED.trace_11.04.11_04.11.12.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb   20971513 Apr 11 04:13 UNHARVESTED.trace_11.04.11_04.13.50.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb   20971516 Apr 11 04:16 UNHARVESTED.trace_11.04.11_04.16.27.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb   20971466 Apr 11 04:18 UNHARVESTED.trace_11.04.11_04.18.55.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb   20971408 Apr 11 04:21 UNHARVESTED.trace_11.04.11_04.21.29.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb   20969680 Apr 11 04:23 UNHARVESTED.trace_11.04.11_04.23.57.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb   20970627 Apr 11 04:26 UNHARVESTED.trace_11.04.11_04.26.24.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb   20971450 Apr 11 04:29 UNHARVESTED.trace_11.04.11_04.29.02.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb   20971478 Apr 11 04:31 UNHARVESTED.trace_11.04.11_04.31.34.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb   20971459 Apr 11 04:34 UNHARVESTED.trace_11.04.11_04.34.09.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb   20971441 Apr 11 04:36 UNHARVESTED.trace_11.04.11_04.36.36.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb   20971219 Apr 11 04:39 UNHARVESTED.trace_11.04.11_04.39.10.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb    1047072 Apr 11 14:54 UNHARVESTED.SystemErr_11.04.11_14.54.28.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb    1048513 Apr 11 15:16 UNHARVESTED.SystemOut_11.04.11_15.16.25.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb    1048537 Apr 11 15:28 UNHARVESTED.SystemOut_11.04.11_15.28.01.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb    1048568 Apr 11 15:39 UNHARVESTED.SystemOut_11.04.11_15.39.43.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb    1048547 Apr 11 15:51 UNHARVESTED.SystemOut_11.04.11_15.51.05.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb    1048485 Apr 11 16:00 UNHARVESTED.SystemOut_11.04.11_16.00.35.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb    1048457 Apr 11 16:10 UNHARVESTED.SystemOut_11.04.11_16.10.25.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb    1048422 Apr 11 16:21 UNHARVESTED.SystemOut_11.04.11_16.21.11.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb    1048412 Apr 11 16:30 UNHARVESTED.SystemOut_11.04.11_16.30.38.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb    1048553 Apr 11 16:42 UNHARVESTED.SystemOut_11.04.11_16.42.00.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb    1048473 Apr 11 16:54 UNHARVESTED.SystemOut_11.04.11_16.54.23.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb    1048519 Apr 11 17:07 UNHARVESTED.SystemOut_11.04.11_17.07.12.log.losls.losasp3f
-rw-r--r--  1 kwdjn jbb    1048507 Apr 11 17:19 UNHARVESTED.SystemOut_11.04.11_17.19.12.log.losls.losasp3f

when i try your command
sudo -u kwdjn find /opt/jboss/logs -name "UNHARVESTED*" | xargs rm -f
it comes back with too many args exception
I can't see why it would get that error.

What happens if you just do:

sudo -u kwdjn find /opt/jboss/logs -name "UNHARVESTED*" >/dev/null

Open in new window

Do you get any error?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.