D
D
DaBags2020-02-07 09:06:51
linux
DaBags, 2020-02-07 09:06:51

How to find and recursively copy files on debian?

Faced a problem. Trying to copy only new files recursively to another directory. I got to this line:
find /dir1 -mtime -1 | xargs cp -t /dir2/;

But the problem is that some files may be in subfolders (for example /dir1/folder1/folder2) then they need to be copied to /dir2/folder1/folder2, but everything is copied to the heap, i.e. to /dir2

Using with the -r switch copies all files in general (regardless of their modification date). Who will tell you what is wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Adamos, 2020-02-07
@DaBags

You should use not naked find, but find + rsync (examples are easy to google).

V
Victor Taran, 2020-02-07
@shambler81

Here is an example

find /home/bitrix/ext_www/shop.wildorchid.ru/ -regex ".*\.\(jpg\|jpeg\|gif\|png\|JPG\|JPEG\|GIF\|PNG\)" -print0 | xargs -0 cp --parents --target-directory ./tmp/backup

All you need to add -mmin or -mtime
create all directories along the way

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question