linux - 如何使用 'mv' 命令移动特定目录中的文件除外?

标签 linux mv

我想知道 - 我如何移动目录中的所有文件,除了特定目录中的文件(因为 'mv' 没有 '--exclude' 选项)?

最佳答案

让我们假设目录结构是这样的,

|parent
    |--child1
    |--child2
    |--grandChild1
    |--grandChild2
    |--grandChild3
    |--grandChild4
    |--grandChild5
    |--grandChild6

我们需要移动文件,使其看起来像,

|parent
    |--child1
    |   |--grandChild1
    |   |--grandChild2
    |   |--grandChild3
    |   |--grandChild4
    |   |--grandChild5
    |   |--grandChild6
    |--child2

在这种情况下,您需要排除两个目录child1child2,并将其余目录移动到child1目录。

使用,

mv !(child1|child2) child1

这会将所有其余目录移动到 child1 目录中。

关于linux - 如何使用 'mv' 命令移动特定目录中的文件除外?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4612157/

相关文章:

linux - 文件名中的旧 rsync 和空格

ansible - 如何使用 Ansible mv 模块

linux - 重命名子文件夹中存在的同名文件以包含子文件夹名称

linux - mv 等效的 rsync 命令

c - 在不复制实例的情况下多次执行程序

linux - 读取是否保证在数据可用时立即返回?

linux - Eth0 用于传入连接,eth1 用于传出连接 NGINX 配置?

linux - 用字符串代替shell中的变量

Linux mkdir、查找和 mv

bash - 使用 mv 删除文件名的一部分