
odt files as follows, while displaying what is being done: $ rm -v !(*.zip|*.odt)ĭelete All Files Except Certain File Extensions Next, you can delete all files in a directory apart from all. zip files interactively: $ rm -i !(*.zip)ĭelete All Files Except Zip Files in LinuxĤ.
#MAC COMMAND LINE LIST ALL FILES WITH FILE EXTENSION HOW TO#
The example below shows how to remove all files other than all. To delete all files with the exception of filename1 and filename2: $ rm -v !("filename1"|"filename2")ĭelete All Files Except Few Files in Linuxģ. 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ġ.


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).
