Linux命令移动目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/868198/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linux command to move a directory
提问by Qooe
My old and new directory have same folders and files inside.
我的旧目录和新目录里面有相同的文件夹和文件。
I try:
我尝试:
mv -if old/* new/*
and get error
并得到错误
mv: cannot move `./xxxxxx' to a subdirectory of itself
mv: 无法将 `./xxxxxx' 移动到自身的子目录
How can I move it?
我怎样才能移动它?
回答by alamar
You should use mv -if old/* new/
without the trailing *
.
您应该使用mv -if old/* new/
不带尾随的*
.
This is because it unrolled to
这是因为它展开到
mv -if old/foo old/bar old/baz new/foo new/bar new/baz
i.e. move everything into new/baz
即把所有东西都移动到 new/baz
This is not what you wanted.
这不是你想要的。
回答by Pawe? Polewicz
reef@localhost:/tmp/experiment$ ls a
11 22 33
reef@localhost:/tmp/experiment$ ls b
22 33
reef@localhost:/tmp/experiment$ ls
a b
reef@localhost:/tmp/experiment$ mv a/* b
reef@localhost:/tmp/experiment$ ls a
reef@localhost:/tmp/experiment$ ls b
11 22 33
It works. What are You trying to achieve? Could You please write a short example of what the input data should look like and what the output data should look like? The truth is I have no idea what You are trying to do :) Help me help You.
有用。你想达到什么目的?你能写一个简短的例子来说明输入数据应该是什么样子,输出数据应该是什么样子吗?事实是我不知道你想要做什么:) 帮我帮你。
回答by Henry Killinger
If you are copying from an ext2/3/4 file system to a FAT32 file system, and a filename has an invalid character for FAT32 naming conventions, you get this terribly annoying and incorrect as hell error message. How do I know? I wrestled with this bug - yes, it's a KERNEL BUG - for 6 hours before it dawned on me. I thought it was a shell interpreter error, I thought it was an "mv" error - I tried multiple different shells, everything. Try this experiment: on an ext file system, "touch 'a:b'" them "mv" it to a FAT32 file system. Try it, you'll enjoy (hate) the results. The same is true for '<' and '>' (\074 and \076).
如果您从 ext2/3/4 文件系统复制到 FAT32 文件系统,并且文件名具有 FAT32 命名约定的无效字符,则会收到非常烦人且不正确的错误消息。我怎么知道?我与这个错误搏斗 - 是的,它是一个内核错误 - 在我意识到之前的 6 个小时。我认为这是一个 shell 解释器错误,我认为这是一个“mv”错误——我尝试了多个不同的 shell,一切。试试这个实验:在一个 ext 文件系统上,“touch 'a:b'”他们“mv”到一个 FAT32 文件系统。试试吧,你会喜欢(讨厌)结果。'<' 和 '>'(\074 和 \076)也是如此。
Thanks for "man mv" - that's a real big help, don't quit your day job.
感谢“man mv” - 这真的是一个很大的帮助,不要辞掉你的日常工作。
回答by Manish Trivedi
Might be you got the answer but above answer is not working for me.... and finally lots of researching I got the answer. (Issue is due to files-ownership)
and just put sudo before the command and its working.... :) Same thing for cp and mv command.
可能你得到了答案,但上面的答案对我不起作用......最后我得到了很多研究的答案。(问题是由于文件所有权)
,只需将 sudo 放在命令及其工作之前...... :) cp 和 mv 命令也是如此。
sudo mv -if old/* new/
回答by Bùi Vi?t Thành
note that mv a/* b/ don't move files .* (file name start with '.') in a/ to b/
请注意, mv a/* b/ 不要将 a/ 中的文件 .*(文件名以 '.' 开头)移动到 b/
ex:
前任:
$ mkdir -p a/d b && touch a/f a/.f a/d/.f
$ mv a/* b/
$ ls -a a/
. .. .f