首页 > 其他分享 >3 Ways to Delete All File in a Directory Except One or Few Files with extensions

3 Ways to Delete All File in a Directory Except One or Few Files with extensions

时间:2023-07-28 09:33:26浏览次数:35  
标签:Files files zip Ways Except extensions extglob rm delete

# https://www.tecmint.com/delete-all-files-in-directory-except-one-few-file-extensions/
# https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html

shopt -s extglob
# s means set

# To delete all files in a directory except filename, type the command blow:
rm -v !("filename")

# To delete all files with the exception of filename1 and filename2:
rm -v !("filename1"|"filename2") 

# The example below shows how to remove all files other than all .zip files interactively:
rm -i !(*.zip)

# you can delete all files in a directory apart from all .zip and .odt files as follows, while displaying what is being done:
rm -v !(*.zip|*.odt)

# Once you have all the required commands, turn off the extglob shell option like so:
shopt -u extglob
# -u means unset


标签:Files,files,zip,Ways,Except,extensions,extglob,rm,delete
From: https://www.cnblogs.com/chenjo/p/17586747.html

相关文章

  • SqlSugar.SqlSugarException: 连接数据库过程中发生错误,证书链是由不受信任的颁发机
    本地代码调试时报错 解决办法:直接在“数据库连接字符串最后面”增加证书信任的配置。;TrustServerCertificate=true ......
  • 【报错修复】HRESULT: 0x80070057 The library hostfxr.dll was found, but loading i
    我写了一个winform程序,拷贝到win7系统上,提示需要下载.net给的链接是https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=win7-x64&apphost_version=5.0.3&gui=true这台win7上不了网我用win10下载了这个链接的桌面运行时windowsdesktop-runtime-5.0......
  • 运行 'Tomcat 8.5.31' 出错: 无法打开调试器端口 (127.0.0.1:62511): java.net.Socket
    多个中间件占用一个端口,修改端口  ......
  • java.security.InvalidKeyException: Illegal key size 的解决方法
    一、原因JDK受版本安全限制,默认只允许128位长度以内的。秘钥长度,如果密钥大于128,会抛出java.security.InvalidKeyException:Illegalkeysize异常.java运行时环境默认读到的是受限的policy文件.文件位于${java_home}/jre/lib/security,这种限制是因为美国对软件出口的控制......
  • Exception: Not found: 'python/cv2/py.typed'
    CopyingfilesfromCMakeoutputcreatingdirectory_skbuild/linux-x86_64-3.6/cmake-install/cv2copying_skbuild/linux-x86_64-3.6/cmake-install/python/cv2/python-3/cv2.abi3.so->_skbuild/linux-x86_64-3.6/cmake-install/cv2/cv2.abi3.socopying_skbuild/linu......
  • 使用filesystemobject获取文件夹及子文件夹下所有文件名
    1OptionExplicit2Dimi3Functionsda(path)4Dimfso5Dimf6Dims7Dimff8Setfso=CreateObject("scripting.filesystemobject")9Setf=fso.getfolder(path)10ForEachsInf.Files11i=i......
  • sql server always on OGG
    如何实现SQLServerAlwaysOnOGG简介在实际的数据库应用中,为了保证高可用性和数据冗余,一项常见的解决方案是使用SQLServerAlwaysOn和OracleGoldenGate(OGG)。SQLServerAlwaysOn提供了高可用性和灾难恢复功能,而OGG则用于实时数据复制和数据同步。在本文中,将详细介绍如何......
  • 2022 javax.management.InstanceNotFoundException: org.springframework.boot:ty
    解决"2022javax.management.InstanceNotFoundException:org.springframework.boot:ty"的步骤对于这个错误,我们需要明确以下几个步骤来解决问题。下面是一个整体的流程表格:步骤描述1确认是否存在相关的InstanceNotFoundException异常2检查org.springframework.boo......
  • Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/common
    Java中的NoClassDefFoundError异常在Java开发中,经常会遇到各种各样的异常,其中之一就是NoClassDefFoundError异常。当我们运行Java程序时,如果出现这个异常,那么通常意味着JVM无法找到所需的类定义。本文将详细介绍NoClassDefFoundError异常的原因、产生的场景以及解决方法。异常原......
  • androidexception 捕获
    Android异常捕获在Android开发中,异常是不可避免的。当应用程序发生异常时,如果不进行处理,将会导致应用崩溃或产生不可预料的错误。因此,合理地捕获和处理异常是Android开发中的重要一环。异常的分类在Java和Android开发中,异常分为两种类型:受检异常(CheckedException)和非受检异常(Un......