Link to home
Start Free TrialLog in
Avatar of WAS
WASFlag for United States of America

asked on

unable to delete large number of files at a time

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





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.
Avatar of farzanj
farzanj
Flag of Canada image

Do this:

files=(ls)

for file in $files
do
sudo rm -rf file
done
Avatar of ikromm
ikromm

try opening a root shell with
sudo bash

Open in new window

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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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*"
Hi,

store files in a variable, like farzani's suggestion:
files=(ls)

If it doesn't work, you can try :
files=`ls`

Then you delete all with :
rm -f $files

No need to loop.

Cheers,
P
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...

P
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sudo find /opt/jboss/logs/System* -type f -exec /bin/rm -f {} \;
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perhaps you could also try the Thunar file manager.
Avatar of WAS

ASKER

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.
Avatar of WAS

ASKER

Tintin,

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?