Linux 如何在特定目录中找到所有的.txt文件,删除它们并使用bash脚本将文件夹打包到archiv中?
我有这个代码,它必须找到所有的.txt文件并删除它们Linux 如何在特定目录中找到所有的.txt文件,删除它们并使用bash脚本将文件夹打包到archiv中?,linux,bash,rm,Linux,Bash,Rm,我有这个代码,它必须找到所有的.txt文件并删除它们 #!/bin/bash find /home/user_name -name "*.txt" | xargs rm 对吗?之后我如何存档文件夹 #!/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 -
#!/bin/bash
find /home/user_name -name "*.txt" | xargs rm
对吗?之后我如何存档文件夹
#!/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
参数的用法除非您了解后果,否则不要使用xargs
find
有一个删除选项:find/home/user_name-name“*.txt”-删除
。用它!了解如何存档文件夹的最佳方法是使用谷歌“how to archive folder linux”