gpt4 book ai didi

bash - 将文件从一个文件夹结构移动到另一个文件夹结构

转载 作者:行者123 更新时间:2023-12-04 18:29:22 24 4
gpt4 key购买 nike

关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。












我们不允许在 Stack Overflow 上提出有关通用计算硬件和软件的问题。您可以编辑问题,使其成为 on-topic对于堆栈溢出。


8年前关闭。







Improve this question




假设我有一个这样的目录结构:

/home/user/Desktop/test/testdir1/
/home/user/Desktop/test/testdir2/
/home/user/Desktop/test/testdir3/

和这里相同的结构:
/home/user/Documents/test/testdir1/
/home/user/Documents/test/testdir2/
/home/user/Documents/test/testdir3/

如何移动文件,例如
/home/user/Desktop/test/testdir3/hello.txt

到各自的目录? (仅移动文件)

最佳答案

我会使用这个命令:

cd /home/user/Desktop/
find . -type d -print0 | xargs -0 -I'{}' echo mkdir -p '/home/user/Documents/{}'
find . -type f -print0 | xargs -0 -I'{}' echo mv '{}' '/home/user/Documents/{}'

引用 {}将确保您的脚本适用于包含空格的文件。

还有 -print0-0将从 find 传递您的文件至 xargs使用 \0作为分隔符。这将确保您的脚本适用于奇怪的文件名。

删除 echo如果脚本似乎对您有好处。使用 echo是测试没有副作用的命令。

关于bash - 将文件从一个文件夹结构移动到另一个文件夹结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22446270/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com