我有一个名为 的文件夹folder1
。它有一堆文件和两个子文件夹subfolder1
和subfolder2
.我想folder1
将subfolder2
除subfolder1
.
我怎样才能做到这一点?
答案1
您可以使用find
和mv
:
这是我的文件夹设置:
$ find folder1
folder1
folder1/subfolder2
folder1/subfolder2/i
folder1/subfolder2/h
folder1/subfolder2/g
folder1/subfolder1
folder1/subfolder1/f
folder1/subfolder1/e
folder1/subfolder1/d
folder1/c
folder1/b
folder1/a
为了模拟您的案例,我想将a
、b
和c
移至subfolder2
:
$ find folder1 -maxdepth 1 -type f -exec mv "{}" folder1/subfolder2 \;
现在,如果我看一下以下内容folder1
:
$ find folder1
folder1
folder1/subfolder2
folder1/subfolder2/a
folder1/subfolder2/b
folder1/subfolder2/c
folder1/subfolder2/i
folder1/subfolder2/h
folder1/subfolder2/g
folder1/subfolder1
folder1/subfolder1/f
folder1/subfolder1/e
folder1/subfolder1/d
答案2
要将 shell中的非目录文件folder1
(不包括隐藏文件)移动到, 您可以执行以下操作:folder1/subfolder2
zsh
mv folder1/*(^/) folder1/subfolder2/
要移动所有文件,无论其类型如何,除了subfolder1
(显然subfolder2
也是如此):
set -o extendedglob # best in ~/.zshrc
mv folder1/^(subfolder1|subfolder2) folder1/subfolder2
要同时移动隐藏文件,请添加D
glob 限定符。
答案3
使用find
和xargs
.读man find xargs
。由于您没有说明文件名是什么样的(嵌入空格、其他有趣的字符),我将使用-print0
.
find folder1 -maxdepth 1 -type f -print0 | \
xargs -0 -r mv --target-directory=subfolder2