linux下删除指定文件夹目录下指定的文件名命令( find 指定的文件夹/ -name this.html~ |xargs rm -rf)

1、有时候需要删除某个文件夹目录下指定的文件名命令,因为有时候里面的子目录包含很多个这样文件名的文件,如果一个一个的删除,很是麻烦,这里有一个很好的方法,本人亲自测试过,可以用,用到的时候很方便高效。

2、命令格式:

           find   指定的文件夹/ -name this.html~ |xargs rm -rf

3、我现在要delete out/目录下的所有fingerprint.default_WFH.so文件。

4、先来看一下目前我的工程out目录下有这么多的fingerprint.default_WFH.so文件。

5、接下来执行命令:find out/  -name fingerprint.default_WFH.so  |xargs rm -rf 命令,看一下结果,out目录下没有文件名是fingerprint.default_WFH.so文件了,都被删除了,很厉害的命令吧。


6、当然这个命令可以扩展,很实用。

   A:删掉所有目录下文件名是fingerprint.default_WFH.so文件:    find /  -name fingerprint.default_WFH.so  |xargs rm -rf 

   B:删掉所有目录下后缀是so文件:    find /  -name *.so  |xargs rm -rf 


  • 3
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
以下是将这些命令转换为Python代码的示例: ```python import subprocess sshd_config_file = '/etc/ssh/sshd_config' ftpusers_file = '/etc/ftpusers' # Update PrintMotd in sshd_config file if subprocess.call('grep -q "PrintMotd" /etc/ssh/sshd_config', shell=True) == 0: subprocess.call("sed -i '/PrintMotd/s/^#//' /etc/ssh/sshd_config", shell=True) subprocess.call("sed -i 's/PrintMotd.*/PrintMotd yes/g' /etc/ssh/sshd_config", shell=True) else: subprocess.call("echo 'PrintMotd yes' >> /etc/ssh/sshd_config", shell=True) # Restart sshd service subprocess.call('service sshd restart', shell=True) subprocess.call('systemctl restart sshd.service', shell=True) # Remove .rhosts, .hosts.equiv and .netrc files subprocess.call('find / -name .rhosts | xargs rm -rf', shell=True) subprocess.call('find / -name .hosts.equiv | xargs rm -rf', shell=True) subprocess.call('find / -name .netrc | xargs rm -rf', shell=True) # Update ftpusers file if subprocess.call('[ -f "/etc/ftpusers" ]', shell=True) == 0: subprocess.call("echo 'root' >> /etc/ftpusers", shell=True) ``` 上述代码首先检查是否存在`/etc/ssh/sshd_config`文件中的`PrintMotd`行,如果存在,则将其注释去除,并将其值设置为`yes`。如果不存在,则在文件末尾添加一行`PrintMotd yes`。 然后,通过执行`service sshd restart`和`systemctl restart sshd.service`命令来重新启动sshd服务。 接下来,使用`find`命令查找并删除系统中的`.rhosts`、`.hosts.equiv`和`.netrc`文件。 最后,检查是否存在`/etc/ftpusers`文件。如果文件存在,则在文件末尾添加一行`root`。 请确保你具有足够的权限来执行这些操作,并将需要修改的文件路径正确添加到`sshd_config_file`和`ftpusers_file`变量中。运行代码后,命令将被执行。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值