Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file toot long 1

Status
Not open for further replies.

adimstec

IS-IT--Management
Nov 27, 2002
52
FR
Hello,

In REP directoy sometimes I have a lot of files
And it happened that the command

find . -name "*.xml" | xargs rm -f

didn't work because of file toot long

I proposed this script

nbre_fichier =`ls -l | wc -l`

If $nbre_fichier > 1500 # this is juste an example
then
cpteur=0

while $cpteur < $nbre_fichier
do
ls -lattr | head -100 | while read FILE
do

rm $FICHIER

cpteur=cpteur+1
done

elsif
ls -lattr | while read FILE
do
rm $FILE
done

fi

Xould you please give me your advice or suggestion

Thankx in advance
 
Whats wrong with
Code:
find .  -name "*.xml"  -exec rm -f {} \;
Ok, so it runs a separate shell for each 'rm' whereas the xargs doesn't but, unless you have severe performance problems it should be fine

Ceci n'est pas une signature
Columb Healy
 
Hello,

When There is too much file, we get the error " file too long" and the files are not erased.

So I try to find another solution to bypass this problem

Thank you
AdimTec

 
What about this instead ?
ls | while read f;do case "$f" in *.xml) rm -f "$f";;esac;done

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Do you mean the file list is too long? Which OS exactly?

I want to be good, is that not enough?
 
hello, hello

yes the file list is too long.
The OS is AIX 5.2 ML 7

The deal is to create a scripts that you can be sure at 100% it will delete all the file inside a directory even if ther is millions ( I exagerate a littel bit)


Thank again
 
hello PHV,

Thank you for your script.
I will use it butu before I need to recreate a situation where I have to manage a lot of files.

Of course, I will keep you informed.

Best Regards
 
PHV,

I tried your script and it work.

Thankx + star

To the next deal !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top