我想从我的笔式驱动器中删除一组在不同文件夹中具有不同文件名的相同扩展名文件,我尝试了以下命令,但它不起作用。
$sudo find /media/<Pendrive> *.jpg | rm -rf *
谁能告诉我从我的 Pendrive 中删除文件的确切命令。
最佳答案
你可以这样写:
sudo find '/media/<Pendrive>' -name '*.jpg' -exec rm -f '{}' ';'
okay, If I'm exporting all the file paths to a text file and now I want to delete the files by using awk commend would it be possible in this case.
如果文本文件名为all_file_paths.txt
,那么您可以这样写:
while IFS= read -r file_to_delete ; do
if [[ "$file_to_delete" == *.jpg ]] ; then
sudo rm -f "$file_to_delete"
fi
done < all_file_paths.txt
(命令 IFS= read -r file_to_delete
从标准输入中读取一行——在本例中来自 all_file_paths.txt
——并将该行存储在变量 $file_to_delete
)。
请注意,如果任何文件路径包含换行符,此方法将出现错误。没有可靠的解决方法,因为您在创建 all_file_paths.txt
时已经放弃了“文件路径结尾”和“文件路径内的换行符”之间的区别。
关于linux - 如何删除不同文件夹中的一组相同扩展名的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13593576/