简体   繁体   English

如何将所有文件和文件夹移动到同一文件夹的子文件夹中

[英]How to move all files and folders into a subfolder of the same folder

in the gitlab-ci for our automatic deployment pipeline, we need to move all files and folders of the old application into a folder "_backup" in the same root directory.在我们的自动部署管道的 gitlab-ci 中,我们需要将旧应用程序的所有文件和文件夹移动到同一根目录中的文件夹“_backup”中。

This is the folder:这是文件夹: 在此处输入图像描述

This is our approach: mv /mnt/test.local/* /mnt/test.local/_backup这是我们的方法: mv /mnt/test.local/* /mnt/test.local/_backup

But the error messages are: mv: can't rename '/mnt/test.local/favicon.ico': No such file or directory但错误信息是: mv: can't rename '/mnt/test.local/favicon.ico': No such file or directory

I think the problem is that I can not move all files and folders (including "_backup"-folder) into the "_backup"-folder.我认为问题在于我无法将所有文件和文件夹(包括“_backup”文件夹)移动到“_backup”文件夹中。 I read about the extglob shell options, but !(_backup) is not working, is there another way?我阅读了有关extglob shell 选项的信息,但是!(_backup)不起作用,还有其他方法吗?

Update : I tried @Kent's approach, but somehow it is not working.更新:我尝试了@Kent 的方法,但不知何故它不起作用。 When I test it locally I get the following error but it works:当我在本地测试它时,我收到以下错误,但它可以工作:

$ find ~/Workspace/testingmove/ -mindepth 1 -maxdepth 1 -path ~/Workspace/testingmove/_backup -prune -o -print|xargs -I{} mv {} -t ~/Workspace/testingmove/_backup
mv: rename /Users/wiesenberg/Workspace/testingmove//_backup to /Users/wiesenberg/Workspace/testingmove/_backup/_backup: Invalid argument
mv: rename -t to /Users/wiesenberg/Workspace/testingmove/_backup/-t: No such file or directory

And when I try it in the gitlab-ci, the following error accurs:当我在 gitlab-ci 中尝试时,会出现以下错误:

$ find /mnt/test.local/ -mindepth 1 -maxdepth 1  -path /mnt/test.local/_backup -prune -o -print|xargs -I{} mv {} -t /mnt/test.local/_backup/
 mv: unrecognized option: t
 BusyBox v1.31.1 () multi-call binary.
 Usage: mv [-fin] SOURCE DEST
 or: mv [-fin] SOURCE... DIRECTORY

Thanks, Marc谢谢,马克

You can use find to exclude the backup directory:您可以使用find排除备份目录:

find /YourHome -mindepth 1 -path /YourHome/_backup -prune -o -print|xargs -I{} cp -r {} /YourHome/_backup

Replace the cp command in xargs with mv if you want to do "mv"如果要执行“ mv ”,请将 xargs 中的cp命令替换为 mv

update更新

find /YourHome -mindepth 1 -maxdepth 1  -path /YourHome/_backup -prune -o -print|xargs -I{} mv {} -t /YourHome/_backup

My workaround is that I created a two subfolders and routed the Webserver to the subfolder.我的解决方法是创建了两个子文件夹并将 Web 服务器路由到子文件夹。

- root
  - _backup
  - website

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将所有文件夹和文件移动到 Linux 目录中具有相同主题名称的文件夹中 - move all the folders and files to the folder with the same subject name in the directory Linux 将文件夹中的所有图像移动到子文件夹,并将文本文件中的所有引用更新到这些图像到其新位置? - Move all images in folder to subfolder, and update all references in text files to those images to their new location? 如何找到各个子文件夹中的所有tar文件,然后将它们解压缩到找到的同一文件夹中? - How to find all tar files in various sub-folders, then extract them in the same folder they were found? 创建与父文件夹同名的子文件夹并将文件移动到其中 - Create subfolder with same name as parent and move files into it 如何在 ssh 控制台中将文件夹的所有文件移动到另一个文件夹? - How to move all files of a folder to another folder in ssh console? 如何根据文件夹名称更改所有文件夹和文件权限? - How to change all folders and files permessions base on folder name? 如何从文件夹和子文件夹压缩新文件 - How to compress new files from folder and subfolder 如何检查文件夹中的所有文件是否具有相同的格式 - How to check if all the files in a folder are of the same format 除了某些文件夹中的文件外,我如何将其所有文件包含在文件夹或目录中? - How do I tar a folder or directory with all of it's files except leave out files from certain folders? 移动和删除文件夹中所有与grep匹配的文件 - Move and delete all files matching grep in folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM