Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Delete file ending with .csv in bash script

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading