简体   繁体   English

从第 n 级子文件夹复制或移动到另一个目录或文件夹

[英]Copy or move from nth level subfolder to another directory or folder

We have a software that adds a wav file and put it on a folder by its date which is buried under several subfolders.我们有一个软件,它可以添加一个wav文件并按日期将它放在一个文件夹中,该文件夹被埋在几个子文件夹下。

For example:例如:

home/user/music/group1/person1/todays date/wav file

home/user/music/group1/person1/yesterdays date/wav file

home/user/music/group1/person2/todays date/wav file

home/user/music/group1/person2/yesterdays date/wav file

Also, the person(n) folder is dynamic which means its created automatically if the software founds someone using that device and creates that folder.此外,person(n) 文件夹是动态的,这意味着如果软件发现有人使用该设备并创建该文件夹,则会自动创建该文件夹。 So for example, if a new user is using the software it will create home/user/music/group1/person3/ .例如,如果一个新用户正在使用该软件,它将创建home/user/music/group1/person3/

How do I move or copy starting from the person(n) folder and move them to a new folder like home/user/new/person1.. home/user/new/person2..如何从 person(n) 文件夹开始移动或复制并将它们移动到新文件夹,例如home/user/new/person1.. home/user/new/person2..

Since the person(n) folder is dynamic I could not just do command like cp person1 newdirectory What i did is find all wav files under group1 folder and cp to new folder but it copies the full path.由于 person(n) 文件夹是动态的,我不能只执行 cp person1 newdirectory 之类的命令我所做的是在 group1 文件夹下找到所有 wav 文件并将 cp 到新文件夹,但它会复制完整路径。

find /home/user/music/group1 -name "*.wav" -type f -exec cp --parents \{\} /home/user/new \;

If i remove --parents it will only copy the files to new folder.如果我删除--parents它只会将文件复制到新文件夹。 how do I copy starting from the person(n) folder to new folder?如何从 person(n) 文件夹开始复制到新文件夹?

thanks @RamanSailopal, i got it to work with find /home/user/music/group1/ -name "person*" -type d -exec cp -pR {}/ /home/user/new \;谢谢@RamanSailopal,我让它与find /home/user/music/group1/ -name "person*" -type d -exec cp -pR {}/ /home/user/new \;

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM