在 bash 脚本中删除以 .csv 结尾的文件
Delete file ending with .csv in bash script
我正在尝试编写一个脚本,从输入文件夹中删除以 .csv 结尾的文件。我试着这样写:
# the direction path of the folder
dirPath=""
# remove the files ending .csv
find $dirPath -type f -name "*.csv" | while read filename; do
rm "$filename"
done
但是它不起作用,我们该如何解决?
你可以find $dirPath -name \*.csv -exec rm -f {}
exec 将让您对找到的每个文件执行 rm。
参考Here
试试这个
find /path/to/directory -type f -name "*.csv" -exec rm -f {} \;
find
有一个 -delete
开关,为什么搞得这么复杂?
find $dirPath -type f -name "*.csv" -delete
我正在尝试编写一个脚本,从输入文件夹中删除以 .csv 结尾的文件。我试着这样写:
# the direction path of the folder
dirPath=""
# remove the files ending .csv
find $dirPath -type f -name "*.csv" | while read filename; do
rm "$filename"
done
但是它不起作用,我们该如何解决?
你可以find $dirPath -name \*.csv -exec rm -f {}
exec 将让您对找到的每个文件执行 rm。
参考Here
试试这个
find /path/to/directory -type f -name "*.csv" -exec rm -f {} \;
find
有一个 -delete
开关,为什么搞得这么复杂?
find $dirPath -type f -name "*.csv" -delete