I usually use find to search for files and analyze the output.
Reading the manual page i learned about nouser & nogroup test expressions.
So i’ve tried some test to find the quicker (or a better way) to remove files with find.
First, lets create a demo dir and a lot of files
# cp -ra /usr /usr.test
# chown -R 10101.10101 /usr.test
How many files do we have ?
# time find /usr.test/ -xdev | wc -l
124298
real 0m0.575s
user 0m0.243s
sys 0m0.363s
Ok, 124.298 files are a lot!
If i want to delete the entire directory via rm, the running time will be:
# time rm -rf usr.test/
real 0m5.883s
user 0m0.287s
sys 0m5.063s
5.88 seconds !
A walk through entire tree path:
# time find /usr.test/ -xdev -nouser > /dev/null
real 0m6.480s
user 0m2.763s
sys 0m3.660s
6.48 secs. It’s faster to remove them!
We now have a base to compare our results.
We will try 3 methods:
a. -delete find option
b. -exec find option
c. xargs via pipe
First Method
# time find /usr.test/ -xdev -nouser -delete
real 0m12.739s
user 0m2.826s
sys 0m9.513s
12.74 secs. Thats the twice amount of time
Second Method
# time find /usr.test -xdev -nouser -exec rm -rf {} ;
real 0m6.307s
user 0m0.253s
sys 0m5.516s
6.3 secs. Same as rm (that was expected by the way).
Third Method
# time find /usr.test/ -xdev -nouser | xargs rm -rf
real 0m4.666s
user 0m1.117s
sys 0m3.426s
4.66 secs!
So xargs is the faster way for the above methods
Εισαγωγικά μαθήματα Linux
( εγκατάσταση / γνωριμία με το λειτουργικό / γνωριμία με την γραμμή εντολών )
Κάθε Τρίτη στον χώρο του hsgr από τις 17.00 μέχρι τις 20.00 θα
πραγματοποιούνται παρουσιάσεις γύρω από το λειτουργικό σύστημα Linux.
Ξεκινάμε την Τρίτη 27 Σεπτεμβρίου 2011 στις 17.00.
Θα παρουσιάσουμε αναλυτικά την εγκατάσταση δύο δημοφιλή διανομών.
Fedora & Ubuntu.
ΥΓ: Φυσικά το hsgr μπορεί να φιλοξενήσει οποιοδήποτε
workshop/παρουσίαση θέλετε κι εσείς να πραγματοποιήσετε.
Evaggelos Balaskas
Unix System Engineer - http://balaskas.gr.