-1
我有這樣的代碼,它必須找到所有.txt文件並刪除它們如何找到特定目錄中的所有.txt文件,將其刪除並使用bash腳本將文件夾壓縮到檔案庫中?
#!/bin/bash
find /home/user_name -name "*.txt" | xargs rm
它是正確的嗎?那我怎樣才能存檔文件夾?
我有這樣的代碼,它必須找到所有.txt文件並刪除它們如何找到特定目錄中的所有.txt文件,將其刪除並使用bash腳本將文件夾壓縮到檔案庫中?
#!/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」-delete「。用它!找出如何歸檔文件夾的最好方法是google「如何歸檔文件夾linux」 – hek2mgl