This is a specific question about using cp
within find
while preserving directory structure. This is the way that seems like it should work, but perhaps there is a way to do it better. The reason I am using find
is because I only want to copy files of a certain age.
I have a directory structure like this. The operating system is Ubuntu 16.04.
folders
folder1
file1.txt
folder2
file1.txt
file2.txt
folder3
file1.txt
I am using the cp
command within the find
command, as so...
find "$pathtofolder"/* -mmin +"$timeinmins" -type f -name "*.txt" -exec cp --parents {} /var/www/website/archives \;
The --parents
flag copies the entire path to the files so I get something like archives/var/www/website/folders/folder1/file1.txt
. This is not what I'm going for. I just want archives/folder1/file1.txt
.
The -R
and -a
flags do not work in this statement within find
. When I use either one of them they seem to stop the copy from happening at all.
What am I doing wrong? Is there a better way to do this?
Thanks very much.