DEV Community

Cover image for How to remove files from a directory having a specific extension in Linux?
MELVIN GEORGE
MELVIN GEORGE

Posted on • Originally published at melvingeorge.me

How to remove files from a directory having a specific extension in Linux?

Originally posted here!

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
Enter fullscreen mode Exit fullscreen mode

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 😃!

Feel free to share if you found this useful 😃.


Top comments (0)