Comments on: 3 Ways to Delete All Files in a Directory Except One or Few Files with Extensions https://www.tecmint.com/delete-all-files-in-directory-except-one-few-file-extensions/ Tecmint - Linux Howtos, Tutorials, Guides, News, Tips and Tricks. Thu, 13 Jul 2023 10:09:36 +0000 hourly 1 By: Yasen https://www.tecmint.com/delete-all-files-in-directory-except-one-few-file-extensions/comment-page-1/#comment-1708572 Wed, 26 Jan 2022 15:38:09 +0000 http://www.tecmint.com/?p=23183#comment-1708572 For me, the working method was “Delete Files Using Bash GLOBIGNORE Variable”.

My goal was to leave only some video and audio files, independent of lower/uppercase:

GLOBIGNORE=*.[Mm][Pp][34]:*.[Mm]4[Aa]:*.[Ww][Aa][Vv]:*.3[Gg][Pp]:*.[Mm][Oo][Vv]:*.[Oo][Gg][Gg]:*.[Oo][Pp][Uu][Ss]:*.[Aa][Aa][Cc]
rm -v *
unset GLOBIGNORE

Hope this will help…

]]>
By: Kyle James https://www.tecmint.com/delete-all-files-in-directory-except-one-few-file-extensions/comment-page-1/#comment-1679182 Thu, 16 Dec 2021 09:05:03 +0000 http://www.tecmint.com/?p=23183#comment-1679182 In reply to Aaron Kili.

A directory is a file, your understanding of Linux and your guide are both jokes. If you can’t make a guide clear then you either don’t understand what you are talking about or you are bad at explaining things. Next time, don’t try what you are not willing to do properly and learn before you teach. Thank you.

]]>
By: sac https://www.tecmint.com/delete-all-files-in-directory-except-one-few-file-extensions/comment-page-1/#comment-1332300 Fri, 08 May 2020 05:33:17 +0000 http://www.tecmint.com/?p=23183#comment-1332300 Hi,

I am trying to delete files from multiple directories through a shell script, in few directory files will come with an extension (.csv) and for few just an alphanumeric names.

Now the problem is, for the files with the extension I am using below line of command and which is working as expected.

# find /Collected_Directory/A/ -type f -name '*.csv' -delete;

but for the directory having files without extension I am using the “rm” command as below which asks permission to delete each file.

# rm /Collected_Directory/B/*

Note:

  1. I can’t change the directory permission.
  2. I don’t want to delete any subdirectories as well.
]]>
By: AvidWarning https://www.tecmint.com/delete-all-files-in-directory-except-one-few-file-extensions/comment-page-1/#comment-1316216 Wed, 12 Feb 2020 06:50:57 +0000 http://www.tecmint.com/?p=23183#comment-1316216 There are typos in topics 6 and 7. Some extensions don’t have *..

That’s dangerous!

Cheers.

]]>
By: Aaron Kili https://www.tecmint.com/delete-all-files-in-directory-except-one-few-file-extensions/comment-page-1/#comment-1246758 Wed, 18 Sep 2019 07:26:57 +0000 http://www.tecmint.com/?p=23183#comment-1246758 In reply to mekkanizer.

@Mekkanizer

Oh sorry about losing your valuable files, but the heading/title is clear enough deleting of files with a particular extension. And the commands all show deleting of files e.g $ rm -v !("filename") not directory name. Next time don’t try what is out of the scope a guide expecting the same results.

]]>