我有一个如下的目录结构:
UltrastarDaily% tree -L 1
.
├── lost+found
├── purple_rsync_bak.06-02-21_06-38-44am
├── purple_rsync_bak.06-02-21_07-41-32pm
├── purple_rsync_bak.07-02-21_08-02-51am
├── purple_rsync_bak.07-02-21_08-17-26am
├── purple_rsync_bak.08-02-21_02-00-06am
├── red_rsync_bak.01-02-21_06-11-39pm
├── red_rsync_bak.06-02-21_06-16-58am
├── red_rsync_bak.06-02-21_06-23-24am
├── red_rsync_bak.06-02-21_06-26-58am
├── red_rsync_bak.06-02-21_06-27-30am
├── red_rsync_bak.06-02-21_06-31-36am
├── red_rsync_bak.06-02-21_06-33-14am
├── red_rsync_bak.06-02-21_06-34-04am
├── red_rsync_bak.06-02-21_06-34-52am
├── red_rsync_bak.06-02-21_06-35-22am
├── red_rsync_bak.06-02-21_06-41-48am
├── red_rsync_bak.06-02-21_07-39-41pm
├── red_rsync_bak.07-02-21_08-01-14am
├── red_rsync_bak.07-02-21_08-17-41am
├── red_rsync_bak.07-02-21_08-38-52am
├── red_rsync_bak.08-02-21_01-56-43am
├── red_rsync_bak.27-01-21_06-13-39pm
├── red_rsync_bak.28-01-21_02-22-31pm
├── red_rsync_bak.30-01-21_12-48-03am
├── rsync-WDPurple.log
├── rsync-WDRed.log
├── WDPurple
└── WDRed
我想从目录.mp4
中递归删除所有文件。...._rsync_bak....
目前我正在使用命令:
find ./ -regextype posix-egrep -regex ".*_rsync_bak.*.mp4" -delete
但是,它并不能确保我只搜索根目录。它还可能mp4
从名称类似...._rsync_bak....
但位于WDPurple
或WDRed
目录内的目录中删除 s。
答案1
将目录包含在搜索路径中
find ./*_rsync_bak.* -type f -name '*.mp4' -print # -delete
一旦您确定它拾取的文件不超过您期望的文件,请替换-print
为-delete
,或简单地附加-delete
到命令末尾