Sometimes you get into a situation where you need to delete all files in a directory or simply cleanup a directory by removing all files except files of a given type (ending with a particular extension).
In this article, we will show you how to delete files in a directory except certain file extensions or types using rm, find and globignore commands.
Before we move any further, let us start by briefly having a look at one important concept in Linux – filename pattern matching, which will enable us to deal with our issue at hand.
In Linux, a shell pattern is a string that consists of the following special characters, which are referred to as wildcards or metacharacters:
*
– matches zero or more characters?
– matches any single character[seq]
– matches any character in seq[!seq]
– matches any character not in seq
No comments:
Post a Comment