Linux/SSH 指令刪除檔案中找到的每個檔案路徑

Linux/SSH 指令刪除檔案中找到的每個檔案路徑

我有一個充滿相對於其自身路徑的文件路徑的文件:

./Talent/152/Resume/a file name.pdf
./Talent/153/Resume/some file name.pdf
./Talent/154/Resume/yet another file name.pdf
... and so on ...

瀏覽此文件中的每一行並將其刪除的適當 shell 命令是什麼?

答案1

xargs -d '\n' rm < listoffiles.txt

答案2

xargs -I{} --arg-file=file rm "{}"

或者

xargs -I{} -a file rm "{}"

引號用空格保護檔案名稱。

答案3

如果您在 Bash shell 中,您可以執行以下操作:

find ./Talent/*/Resume/* -exec rm {} \;

或者如果你想刪除超過 7 天的文件,你可以加入 -mtime 參數,如下所示:

find ./Talent/*/Resume/* -mtime +7 -exec rm {} \;

相關內容