似乎已经以多种方式提出了这个问题。但是我想用rm
代替find
。
我遵循了许多有关如何使用的解释find
,但是在执行find
命令时遇到了问题。当我使用定位时,我得到以下输出:
maxgitt@mgpc:/etc$ locate omero
/etc/nginx/conf.d/omeroweb.conf
/etc/rc0.d/K01omero-web
/etc/rc1.d/K01omero-web
/etc/rc2.d/S03omero-web
/etc/rc3.d/S03omero-web
/etc/rc4.d/S03omero-web
/etc/rc5.d/S03omero-web
/etc/rc6.d/K01omero-web
但是,当我尝试使用find删除相应的文件时,出现以下错误。
maxgitt@mgpc:/etc$ find -type f -name '*omero*'
./etc/rc0.d/K01omero-web
./etc/rc1.d/K01omero-web
./etc/rc2.d/S03omero-web
./etc/rc3.d/S03omero-web
./etc/rc4.d/S03omero-web
./etc/rc5.d/S03omero-web
./etc/rc6.d/K01omero-web
find: ‘./cups/ssl’: Permission denied
find: ‘./ppp/peers’: Permission denied
find: ‘./polkit-1/localauthority’: Permission denied
find: ‘./ssl/private’: Permission denied
./nginx/conf.d/omeroweb.conf
find: ‘./chatscripts’: Permission denied
find: ‘./docker’: Permission denied
所以我选择使用命令:
maxgitt@mgpc:/etc$ sudo rm -rf /etc/*/*omero-web*
但我希望能够删除etc/
目录及其相应子目录中的所有文件。由于我的hackyrm
命令,我只剩下一个文件:
maxgitt@mgpc:/etc$ locate omero
/etc/nginx/conf.d/omeroweb.conf
使用sudo
删除之前,请务必先空试,以确保删除的内容不超出讨价还价。
sudo find -type f -name '*omero*'
然后,假设清单看起来不错
sudo find -type f -name '*omero*' -delete
或指定要搜索的位置(您已经知道这些文件在/ etc中)
sudo find /etc -iname '*omero*' -delete
-delete快于-exec rm {} \;
或-print0 | xargs -0 rm
因为它没有产卵另一个进程。
编辑:从评论
for i in $(locate omero) ; do rm $i ; done
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句