Often you may want to use Bash to delete all files in a directory that have a specific extension.
You can use the following syntax to do so:
find . -type f -name '*.csv' -delete
This particular example will delete all files in the current directory that have a .csv file extension.
Here is what the various commands do:
- find .: Match all items in current directory
- -type f: Match only the files
- -name ‘*.csv’: Match only files that have .csv extension
- -delete: Delete each of the matched files
Note that you can also replace find . with find /some/directory/path to match all files in a specific directory.
The following example shows how to use this syntax in practice.
Example: How to Delete All Files with Specific Extension in Bash
Suppose that our current directory is located at the following path:
- c:/users/bobbi/data2
We can use the ls command to first view all items in this directory:

We can see that this directory contains the following files:
- coaches.txt
- leagues.csv
- owners.txt
- players.txt
- rosters.csv
Suppose that we would like to delete all files in this directory that have a .csv extension.
We can use the following syntax to do so:
find . -type f -name '*.csv' -delete
The following screenshot shows how to use this syntax in practice:

Notice that when we use the ls command again to view the updated files in the directory we can see that all files that had a .csv extension have been deleted.
Feel free to replace .csv with any other specific file extension that you would like to match.
Related Tutorials
The following tutorials explain how to perform other common tasks in Bash:
Bash: Use find and Exclude Specific Directory
Bash: How to List All Files in Folder Without Extension
Bash: How to Rename Extension of Multiple Files
