如何使用"mv"命令移动除特定目录中的文件以外的文件? [英] How to use 'mv' command to move files except those in a specific directory?

查看:1480
本文介绍了如何使用"mv"命令移动除特定目录中的文件以外的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道-如何移动目录中除特定目录中的那些文件以外的所有文件(因为"mv"没有"--exclude"选项)?

I am wondering - how can I move all the files in a directory except those files in a specific directory (as 'mv' does not have a '--exclude' option)?

推荐答案

让我们假设dir结构类似于

Lets's assume the dir structure is like,

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

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

And we need to move files so that it would appear like,

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

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

In this case, you need to exclude two directories child1 and child2, and move rest of the directories in to child1 directory.

使用

mv !(child1|child2) child1

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

This will move all of rest of the directories into child1 directory.

这篇关于如何使用"mv"命令移动除特定目录中的文件以外的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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