In Linux, deleting files that end with a specific extension requires typing the rm
command followed by a space and specifying the extension of the file after a wildcard character (*
).
For example, let's say you have to delete only the .txt
files (or text files) in a directory and not delete any other files types, here we can use the rm
command like this,
# Delete only those files with
# .txt extension in Linux
rm *.txt
Executing the above command will delete all the files having the .txt
extension type leaving all the other file types.
See the execution of the above command live in repl.it.
That's all 😃!