[OE-core] Efficient ways to delete a build directory

Robert Yang liezhi.yang at windriver.com
Thu Jan 3 02:44:09 UTC 2019


We have the following 3 ways to delete a build directory:
* rm -fr build
* find -delete build
* rsync -a --delete emtpy_dir build

I've heard that rsync is the fastest way for removing millions of files,
so I did a test on removing the build dir:

* Host info:
   $ cat /etc/issue
   Ubuntu 14.04.4 LTS \n \l

   $ rm --version
   rm (GNU coreutils) 8.21

   $ find --version
   find (GNU findutils) 4.4.2

   $ rsync --version
   rsync  version 3.1.0  protocol version 31

* Do a build
   $ . oe-init-build-env build
   $ bitbake core-image-minimal

* Size:
   $ du -sh build
   22G

* Files amount:
   $ find build -type f | pv -l  >/dev/null
   2.61M

   2.61 millions files

* Make 3 copies:
   $ cp -r build build_copy_1
   $ cp -r build build_copy_2
   $ cp -r build build_copy_3

* Remove them:
   $ time rm -fr build_copy_1/
   real    3m26.249s
   user    0m4.612s
   sys     1m1.704s

   $ time find build_copy_2/ -delete
   real    3m6.771s
   user    0m4.236s
   sys     0m59.592s

   $ time rsync -a --delete empty/ build_copy_3/
   real    5m7.115s
   user    0m8.612s
   sys     1m13.928s

We can see that find -delete is the fastest way, rsync is the slowest one,
and rm is close to find. Maybe it is because find and rsync are improved in
nowadays, so they are faster than rsync.

-- 
Thanks

Robert


More information about the Openembedded-core mailing list