bash 如何将文件上移一个目录并删除旧目录而无需专门命名文件?

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

How can I move files up one directory and delete old directory without specifically naming files?

bashshellcommand-line

提问by Jeff Severns Guntzel

I use a shell script that takes a single directory, called NewData, with whatever is inside of it, and creates this:

我使用一个 shell 脚本,它接受一个名为 的单个目录NewData,其中包含其中的任何内容,并创建以下内容:

enter image description here

在此处输入图片说明

There is one step I want to add, and I am not sure how to do it. I want to move the contents of NewDataand NewDataCopyinto their respective parent directories (ProtectedOrigand Data) and delete NewDataand NewDataCopy. What command(s) would I add to my script to do this without specifically naming the files to be moved (they will be different every time I run the script)?

我想添加一个步骤,我不知道该怎么做。我想移动的内容NewDataNewDataCopy到各自的父目录(ProtectedOrigData),并删除NewDataNewDataCopy。我会在脚本中添加哪些命令来执行此操作,而无需专门命名要移动的文件(每次运行脚本时它们都会不同)?

If it would help, you can have a look at the script here. I'm grateful for whatever assistance I can get!

如果有帮助,您可以在此处查看脚本。我很感激我能得到的任何帮助!

回答by drysdam

You can move everything without naming the files specifically by using a "glob" (aka a "wildcard"). That's a *.

您可以使用“glob”(又名“通配符”)移动所有内容而无需专门命名文件。那是一个*

So let's say you are in DataDirectory. You can move everything from Data/NewDataCopyup to Databy doing this: mv Data/NewDataCopy/* Data/. Then delete with a rmdir Data/NewDataCopy.

因此,假设您在DataDirectory. 您可以通过执行以下操作将所有内容从Data/NewDataCopyup移动到Datamv Data/NewDataCopy/* Data/。然后用 删除rmdir Data/NewDataCopy

Starting from DataDirectorythen to do everything you'd do this:

从开始DataDirectory,然后做你会做这一切:

mv Data/NewDataCopy/* Data/
rmdir Data/NewDataCopy
mv ProtectedOrig/NewData/* ProtectedOrig/
rmdir ProtectedOrig/NewData