DEV Community

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

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

MELVIN GEORGE
Hi, I'm Melvin George, A web developer, and a blogger.
Originally published at melvingeorge.me ・1 min read

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 πŸ˜ƒ.


Discussion (0)