我不太熟悉,find
无意中删除了大量文件。我想知道是否有更有经验的人可以解释我哪里出错了。
我想清理所有的.DS_Store
和._.DS_Store
文件我的MacBook的Finder是barfing都在我的Raspbian桑巴份额。
-L
.sudo
.我运行了以下命令以确保它find
针对的是正确的文件:
hydraxan@raspberry:~ $ sudo find -L . -maxdepth 255 -name \*DS_Store\*
./.DS_Store
./Downloads/USBHDD1/._.DS_Store
./Downloads/USBHDD1/.DS_Store
./Downloads/USBHDD1/backups/ALAC/._.DS_Store
./Downloads/USBHDD1/backups/ALAC/Jeff Van Dyck - Assault Android Cactus OST/._.DS_Store
./Downloads/USBHDD1/backups/ALAC/Jeff Van Dyck - Assault Android Cactus OST/.DS_Store
./Downloads/USBHDD1/backups/ALAC/.DS_Store
./Downloads/USBHDD1/backups/._.DS_Store
./Downloads/USBHDD1/backups/.DS_Store
./Downloads/USBHDD1/backups/OriginalMusic/._.DS_Store
./Downloads/USBHDD1/backups/OriginalMusic/.DS_Store
./Downloads/USBHDD1/backups/OriginalMusic/FLAC/.DS_Store
./Downloads/USBHDD1/backups/Storage/._.DS_Store
./Downloads/USBHDD1/backups/Storage/.DS_Store
./Downloads/OriginalMusic/._.DS_Store
./Downloads/OriginalMusic/.DS_Store
./Downloads/OriginalMusic/FLAC/.DS_Store
./Downloads/ALAC/._.DS_Store
./Downloads/ALAC/Jeff Van Dyck - Assault Android Cactus OST/._.DS_Store
./Downloads/ALAC/Jeff Van Dyck - Assault Android Cactus OST/.DS_Store
./Downloads/ALAC/.DS_Store
Run Code Online (Sandbox Code Playgroud)
一切看起来都不错!
然后我添加了-delete
标志以find
删除它找到的文件:
hydraxan@raspberry:~ $ sudo find -L . -maxdepth 255 -delete -name \*DS_Store\*
find: cannot delete `./Documents': Not a directory
find: cannot delete `./Pictures': Not a directory
find: cannot delete `./Music': Not a directory
Run Code Online (Sandbox Code Playgroud)
一旦我意识到它出于某种原因试图删除我的符号链接,我就猛击Ctrl+C
并保存了大约一半的数据。
文档、图片和音乐是敬酒。它可能正在处理我几乎将所有内容都放入的巨大下载文件夹。
为什么要find
删除所有这些文件?我是不是放-delete
错地方了?
SYN*_*SYN 15
您的答案在find
联机帮助页中。
删除选项在您的姓名过滤器之前处理。
-delete
Delete files; true if removal succeeded. If the removal failed,
an error message is issued. If -delete fails, find's exit sta?
tus will be nonzero (when it eventually exits). Use of -delete
automatically turns on the -depth option.
Warnings: Don't forget that the find command line is evaluated
as an expression, so putting -delete first will make find try to
delete everything below the starting points you specified. When
testing a find command line that you later intend to use with
-delete, you should explicitly specify -depth in order to avoid
later surprises. Because -delete implies -depth, you cannot
usefully use -prune and -delete together.
Run Code Online (Sandbox Code Playgroud)
您可以将删除选项移动为命令的最后一个
或者,你可以使用类似的东西
find /path -name "*pattern*" | xargs rm -f
Run Code Online (Sandbox Code Playgroud)
或者
find /path -name "*pattern*" -exec rm -f {} \;
Run Code Online (Sandbox Code Playgroud)