Home > Software design >  Delete file ending with .csv in bash script
Delete file ending with .csv in bash script

Time:04-14

I am trying to write a script that remove files ending .csv from an input folder. I try to write this:

# the direction path of the folder
dirPath="$1"
# remove the files ending .csv
find $dirPath -type f -name "*.csv" | while read filename; do
rm "$filename"
     done

But it's not working, how can we fix it?

CodePudding user response:

Try this

find /path/to/directory -type f -name "*.csv" -exec rm -f {} \;

CodePudding user response:

Why make it so complicated, while find has a -delete switch?

find $dirPath -type f -name "*.csv" -delete

CodePudding user response:

you can do find $dirPath -name \*.csv -exec rm -f {}

exec will let you to execute rm on each file found.

Refer Here

  • Related