[ale] best solution for removing large # of files on NFS share.

Bob Toxen transam at verysecurelinux.com
Wed Jun 29 12:27:43 EDT 2022


Efficiency is very close since neither involves a fork/exec sequence (which is very expensive).
Do whichever you are most comfortable with.

Since I am very paranoid about "rm -rf" in case of mistyping, I might use the find
with a -name thusly:

  find dir1 -type f -name '*.stupid_log_file_ext' -delete

I might add before the -delete and put in root's crontab:

  ! -mtime +365

The "find" certainly needs to do a "stat()" system call which has a slight overhead.
However, the "rm -rf" almost certainly has do a "stat()" as well to determine if
each file is a directory (that requires a "rmdir()" system call instead of an
"unlink()" system call.

The "rm -rf" might be smart enough to just do an "unlink()" call and if it
returns the error EISDIR (error it is a directory) it then would recursively
delete the files and dirs in that dir and then do an "unlink()" call.

In either case each file's (and dir's) inode would need to be read off of
disk to know the disk blocks to put on the free list.

Bob

On Wed, Jun 29, 2022 at 11:18:24AM -0400, Geoffrey Myers via Ale wrote:
> Looking for some advice for the best way to delete a large number of
> files spread across a large number of directories on an NFS share.  RHEL7

> There are 6 directories of the form:

> dir1/month/day/hour/minute/
> .
> .
> dir6/month/day/hour/minute/


> There are only files in the minute???s directories.

> which is a more efficient solution?

> 1.	find dir1 -type f -delete
> 2.	rm -rf dir1


> Regarding #2, the directories will be recreated by the application.

> --
> Until later, Geof
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> https://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo


More information about the Ale mailing list