我有这段代码,必须找到所有.txt文件并删除它们
#!/bin/bash
find /home/user_name -name "*.txt" | xargs rm
这是对的吗?之后如何存档文件夹?
答案 0 :(得分:1)
#!/bin/bash
find /home/user_name -type f -name "*.txt" -exec rm {} \;
# for your specific use case, you could also do
# find /home/user_name -type f -name "*.txt" -delete
# as @hek2mgl pointed out.
# You can have a more restricted search by using -type f
# You can archive the folder using the zip command like below
zip -r user_name.zip /home/user_name
注意:阅读zip
的联机帮助页,了解-r
参数的使用情况