Skip to contentSkip to conversation

Deleting many files from a directory

DISCUSSION Mário Gamito 7 participants 9 messages Dec 23, 2004 – Dec 30, 2004

lore
Share & tools
lore
#0 lore raw

Hi,

When we have too many files in a directory, let's say thousands, we cannot rm -f * on them. The system says there are too many files. So, one must go through a tedious process of deleting by parts.

Is there a way to wipe them all at onde ?

Thank you.

Warm Regards.

Signature · 12 lines
Mário Gamito
Administração de sistemas e desenvolvimento
Netual - Multimédia e Telecomunicações, Lda.
Rua João Afonso, Nº1
3800-198 Aveiro - Portugal
Tel. +351 234 371 431 / Fax. +351 234 371 438
E-mail: [email protected]
www.netual.pt
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw
Quoted 5 lines · M?rio Gamito

When we have too many files in a directory, let's say thousands, we cannot rm -f * on them. The system says there are too many files. So, one must go through a tedious process of deleting by parts.

Is there a way to wipe them all at onde ?

Multiple ways to do it really, but one would be:
---
find /path/to/delete -exec rm -f \{\} \;

Signature · 18 lines
Mark Nipper                                                e-contacts:
4475 Carter Creek Parkway                           [email protected]
Apartment 724                               http://nipsy.bitgnome.net/
Bryan, Texas, 77802-4481           AIM/Yahoo: texasnipsy ICQ: 66971617
(979)575-3193                                      MSN: [email protected]

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GG/IT d- s++:+ a- C++$ UBL++++$ P--->+++ L+++$ !E---
W++(--) N+ o K++ w(---) O++ M V(--) PS+++(+) PE(--)
Y+ PGP t+ 5 X R tv b+++@ DI+(++) D+ G e h r++ y+(**)
------END GEEK CODE BLOCK------

---begin random quote of the moment---
"Suppose you were an idiot and suppose you were a member of
Congress.  But I repeat myself."
 -- Mark Twain
----end random quote of the moment----
#2 lore raw
In reply to Mário Gamito

Hi,

Quoted 5 lines · --On Thursday, December 23, 2004 09:40:12 +0000 Mário Gamito…

When we have too many files in a directory, let's say thousands, we cannot rm -f * on them. The system says there are too many files. So, one must go through a tedious process of deleting by parts.

Is there a way to wipe them all at onde ?

To remove all files in all subdirectories do:

find /path/ -type f | xargs -n 50 rm

Thats much faster than 'find ...-exec...'

Cheers,
Harry

--

1024D/40F14012 18F3 736A 4080 303C E61E 2E72 7E05 1F6E 40F1 4012

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GIT/S dx s: a C++ ULS++++$ P+++ L+++$ !E W++ N+ o? K? !w !O !M V PS+ PE Y? PGP+++ t+ 5-- X+ R+ !tv b++ DI++ D+ G e* h r++ y++ ------END GEEK CODE BLOCK------

#3 lore raw
Quoted 5 lines · On 23 Dec 2004, [email protected] wrote:

To remove all files in all subdirectories do:

find /path/ -type f | xargs -n 50 rm

Thats much faster than 'find ...-exec...'

That can get a little strange though if files have spaces
or other strange characters in their names.

Signature · 17 lines
Mark Nipper                                                e-contacts:
4475 Carter Creek Parkway                           [email protected]
Apartment 724                               http://nipsy.bitgnome.net/
Bryan, Texas, 77802-4481           AIM/Yahoo: texasnipsy ICQ: 66971617
(979)575-3193                                      MSN: [email protected]

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GG/IT d- s++:+ a- C++$ UBL++++$ P--->+++ L+++$ !E---
W++(--) N+ o K++ w(---) O++ M V(--) PS+++(+) PE(--)
Y+ PGP t+ 5 X R tv b+++@ DI+(++) D+ G e h r++ y+(**)
------END GEEK CODE BLOCK------

---begin random quote of the moment---
"All mail clients suck.  This one just sucks less."
 -- author of the Mutt e-mail client
----end random quote of the moment----
#4 lore raw
Quoted 8 lines · Mark Nipper
Quoted 5 lines

To remove all files in all subdirectories do:

find /path/ -type f | xargs -n 50 rm

Thats much faster than 'find ...-exec...'

That can get a little strange though if files have spaces
or other strange characters in their names.

Using:

find /path -type -f -print0 | xargs -0 -n 50 rm

will cope with filenames which contain whitespace.

Signature · 1 line
Glynn Clements <[email protected]>
#5 lore raw
In reply to Mário Gamito

do a loop

for i in filenames*
do
rm $i
done

Quoted 25 lines · Mário Gamito

Hi,

When we have too many files in a directory, let's say thousands, we cannot rm -f * on them. The system says there are too many files. So, one must go through a tedious process of deleting by parts.

Is there a way to wipe them all at onde ?

Thank you.

Warm Regards.

Signature · 12 lines
Mário Gamito
Administração de sistemas e desenvolvimento
Netual - Multimédia e Telecomunicações, Lda.
Rua João Afonso, Nº1
3800-198 Aveiro - Portugal
Tel. +351 234 371 431 / Fax. +351 234 371 438
E-mail: [email protected]
www.netual.pt
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

-----------------
Hal Wigoda

-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw
Quoted 6 lines · Hal Wigoda

do a loop

for i in filenames*
do
rm $i
done

Put quotes around the variable, i.e.:

	rm "$i"

otherwise it won't handle filenames which contain whitespace.

Shell variables should always be quoted unless you actually want values which contain whitespace to be split into multiple words.

Signature · 1 line
Glynn Clements <[email protected]>
#7 lore raw
In reply to Mário Gamito
Quoted 11 lines · Mário Gamito

Hi,

When we have too many files in a directory, let's say thousands, we cannot rm -f * on them. The system says there are too many files. So, one must go through a tedious process of deleting by parts.

Is there a way to wipe them all at onde ?

Thank you.

Warm Regards.

if is Just a directory, call rm with the name of the directory like that
rm -rf /dirname
where the r is for recursive, sometimes find hangs with more than 65535 files in a single directory in some older versions (I still using some ones).

If you have a lot of folders with a lot of files, then:

find -type d | while read dir; do rm -rf "$dir" ; done

"" in $dir is for names with spaces.

Mery Christmas

Signature · 9 lines
-------
Gustavo Guillermo Perez
Compunauta uLinux
www.userver.tk

-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#8 lore raw

your can also try:

for f in a b c d e f g h i j k l m n o p q r s t u v w x y z do rm ${f}*
done

you might need to repeat for capitals and numbers.

Quoted 28 lines · Gustavo Guillermo Perez
Quoted 11 lines · Mário Gamito

Hi,

When we have too many files in a directory, let's say thousands, we cannot rm -f * on them. The system says there are too many files. So, one must go through a tedious process of deleting by parts.

Is there a way to wipe them all at onde ?

Thank you.

Warm Regards.

if is Just a directory, call rm with the name of the directory like that
rm -rf /dirname
where the r is for recursive, sometimes find hangs with more than 65535 files in a single directory in some older versions (I still using some ones).

If you have a lot of folders with a lot of files, then:

find -type d | while read dir; do rm -rf "$dir" ; done

"" in $dir is for names with spaces.

Mery Christmas

Signature · 9 lines
John Julian
Computer Geek
cell: 248-376-6364
pager: 800-621-4951

-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html