Bash:复制+重命名文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33343840/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 13:49:14  来源:igfitidea点击:

Bash: duplicate + rename folder

bashshelldirectoryrename

提问by Manfredo

Suppose I have a folder named my_folder_oldin /path/to/folder, how can I create a duplicate named my_folder_newin the same directory?

假设我有一个名为my_folder_oldin的文件夹/path/to/folder,如何my_folder_new在同一目录中创建一个重复的文件夹?

EDIT

编辑

Moreover if my_folder_newalready exists, my_folder_oldis created inside the first and not substituted. Why is this happening?

此外,如果my_folder_new已经存在,my_folder_old则在第一个内部创建而不被替换。为什么会这样?

回答by Noproblem

Tutorial copy files, folder link: link

教程复制文件,文件夹链接:链接

Manual cp command : Link

手动 cp 命令:链接

cp -frp /path/to/folder/my_folder_old -T /path/to/folder/my_folder_new

   -f, --force
          if an existing destination file cannot be opened, remove it
          and try again (this option is ignored when the -n option is
          also used)
   -p     same as --preserve=mode,ownership,timestamps
   -R, -r, --recursive
          copy directories recursively
   -T, --no-target-directory
          treat DEST as a normal file

Though if my_folder_new already exists, my_folder_old is created inside the first and not substituted. Why is this happening?

尽管如果 my_folder_new 已经存在,则 my_folder_old 是在第一个内部创建的而不是被替换的。为什么会这样?

The reason why is this happening because, my_folder_new already created. Doing same cp command it will see as new path, /path/to/folder/my_folder_new/

之所以会发生这种情况,是因为 my_folder_new 已经创建。执行相同的 cp 命令,它将看到新路径,/path/to/folder/my_folder_new/