Search code examples
bashalphanumericrm

bash, remove files with letters in the filename


I have a directory fill of files like the following:

1000.csv
1001.csv
aaa.csv
aac.csv

I want to remove the files like aaa.csv and aac.csv (basically anything that has [letters].csv, but keep the files that have [numbers].csv

Is there a way to do this in bash?


Solution

  • This should do what you ask but with the caveat that this is a very dangerous command so make sure you designate the right path!

    find ./ -type f -name '*[a-z]*.csv' | xargs rm
    

    "./" is where you should put the path to the directory of the files you want to remove. This will also remove any file that contains letters. Even 12h.csv.