无法删除文件夹中除FileA以外的所有其他内容 [英] Unable to remove everything else in a folder except FileA

查看:61
本文介绍了无法删除文件夹中除FileA以外的所有其他内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何删除文件夹中除FileA以外的所有其他内容,甚至是隐藏文件? 我使用Ubuntu.

How can I remove everything else in a folder except FileA, even hidden files? I use Ubuntu.

我尝试了以下失败

rm [^fileA]

推荐答案

使用extglob.假设FileA是常规文件(即不是以.开头),则可以执行以下操作:

Use extglob. Assuming that FileA is a regular file (i.e. does not begin with a .), then you can do:

shopt -s extglob  # Enable extglob
rm !(FileA) .*  # Remove all regular files not named FileA and all hidden files

如果FileA是隐藏文件,则它将不起作用,因为!( pattern )构造仅创建所有不符合 pattern的常规文件的列表.

If instead FileA is a hidden file, this won't work, since the !(pattern) construct only creates a list of all regular files not matching pattern.

这篇关于无法删除文件夹中除FileA以外的所有其他内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆