

So it is probably impossible to create the hard link to a directory in the first place and find will have nothing to follow. This is the dangerous choice, anyways.įor hard links, find will follow the link to another file but please note that hard linking to a another directory "will probably fail " as see into man ln for GNU ln : -d, -F, -directoryĪllow the superuser to attempt to hard link directories (note: will probablyįail due to system restrictions, even for the superuser) So this example is likely to not be a prolem, unless you force find to follow soft links using the -L flag. To understand the difference between the two please see Hard link and Symbolic links in Unix or google it up.įor soft links (the most used type anyways) both GNU find and BDS find does not follow simbolic links unless is used a a specific -L flag to force symbolic link following. The example "someone has maliciously created a link " given into Additional considerations around security is not totally accurate both about Unix hard links and for Unix soft links. NOTE & Disclamer : this have to be a comment to slm answer but righ now I can't do comments yet. There is an slight inaccuracy into slm answer. Deleting lots of files with find - Debian Administrators Blog.+, but this is insecure and isn't supported by versions of GNU findutils prior to 4.2.12.
Where to buy filemass portable#
The most efficient portable alternative is -exec. The -delete action is not completely portable. Using xargs -0 can be similar in performance, but it is not as secure. The fastest and most secure way to delete files with the help of find is to use -delete.

This issue exists with any of the methods for deleting files, except for the -delete option (method #1). When the above command runs, the /etc directory will also be deleted. Unbeknownst to you, someone has maliciously created a link to the /etc directory under /var/tmp/somedir. svn -type d -prune ")" -type f -print -depthįor this reason, when using -delete, care must be taken. svn -type d -prune ")" -type f -printīut because -delete includes a -depth switch, the files that would actually be getting dealt with: $ find. I might use the following command to accomplish this: $ find. What does this mean? Here's an example of how -delete can burn you if you're not careful.įor example, say I have a subversion work directory where I want to clean up some files, but leave its. NOTE: One thing to keep in mind with this approach, the use of -delete implies also the switch -depth. The `-delete' action was introduced by the BSD family of operating systems. Has the same security advantages as the `-execdir' The directory containing the entry to be deleted, so the-delete' action This alternative is more efficient than any of the -exec' or-execdir'Īctions, since it entirely avoids the overhead of forking a new processĪnd using exec' to run/bin/rm'. The `-delete' action: find /var/tmp/stuff -mtime +90 -delete The most efficient and secure method of solving this problem is to use

o -iname '*.jpeg' -o -iname '*.gif' -deleteĪs others have mentioned within this Q&A, this method is the fastest and least resource intensive. type f -iname '*.xml' -o -iname '*.png'\ There are basically 4 ways in which to approach this problem using find.
