I have a hard drive that contains about 300,000 x 3 files that were written by a recovery program.
Some of these files are in the format:
.doc.apple.quarantine
These are easy to remove:
find . -type f -name '*.apple.quarantine' -delete
But others are more difficult because they have the phrase
_AFP_Afpinfo
which may have been written after the file extension, e.g.
happybirthday.mp3._AFP_afpinfo
or just
happybirthday_AFP_Afpinfo
I would like to delete the third type of file, i.e.:
happybirthday_AFP_Afpinfo
so my question is whether this Unix command will delete all files that contain the characters AFP_Afpinfo
?
find . -type -f 'AFP_Afpinfo' -delete
I tested
-find . -type -f -name 'epub' -print
and no files displayed.
I tried
-find -type -f -name 'epub' -print
and files displayed. So the use of the period after find
was incorrect.
After running 1/2 hour or so, running:
find -type f -name '_AFP_Afpinfo'
the following error was displayed:
find: './.Trash-1000/files': Input/output error
I checked that directory and it's full of AFP_Afpinfo
files.
find
command without the-delete
beforehand and see what files show up in the run (pipe toless
if the list is big).find . -type f -name EXPRESSION -print
which just prints the name of the files, and if the list of files is long you can pipe it toless
and review if you are finding any files you should not be finding and adjust your expression accordingly._AFP_Afpinfo
but only where it is not preceded by a period? if so, you can use-name '*[^.]_AFP_Afpinfo'
or if you prefer\( -name '*_AFP_Afpinfo' ! -name '*._AFP_Afpinfo' \)
-delete
should be replaced with-depth -print
, since-delete
implies-depth
whether you want it or not. (As a result I have found there are occasions with complex filters where-exec rm -f {} +
is necessary instead of-delete
, for example with-name … -prune
)