![mac command line delete directory with files mac command line delete directory with files](https://www.addictivetips.com/app/uploads/2011/01/Infected-file.jpg)
To delete all files in a directory except filename, type the command below: $ rm -v !("filename")ĭelete All Files Except One File in LinuxĢ. To use them, enable the extglob shell option as follows: # shopt -s extglobġ. !(pattern-list) – matches anything except one of the given patterns.
![mac command line delete directory with files mac command line delete directory with files](https://flylib.com/books/2/585/1/html/2/images/0321305264/graphics/19fig26.gif)
– matches one of the specified patterns.+(pattern-list) – matches one or more occurrences of the specified patterns.?(pattern-list) – matches zero or one occurrence of the specified patterns.*(pattern-list) – matches zero or more occurrences of the specified patterns.The different extended pattern matching operators are listed below, where pattern-list is a list containing one or more filenames, separated using the | character: There are three possible methods we shall explore here, and these include: Delete Files Using Extended Pattern Matching Operators In Linux, a shell pattern is a string that consists of the following special characters, which are referred to as wildcards or metacharacters: Suggested Read: Use find Command to Search Multiple Filenames/Extensions in Linux
#Mac command line delete directory with files how to
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.īefore 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. 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).