0

I want to copy all the files newer than another one from their original location /lib/ into another destination /dest/lib/

To identify these files I simply use:

$ cd /lib/
$ find . -newer foobar
./foo/bar.py
./bar/foo/bar/foo.py
...

Unfortunately I cannot simply use this command because cp does not know how to create folders on the fly.

So I used this command:

find /foo -type f -newer foobar | \
    xargs -n1 -I% sh -c 'mkdir -vp `dirname /dest/%` && cp -v % /dest/%'

This looks very complicated and is incredibly slow. Is there a better solution?

nowox
  • 22,446
  • 24
  • 118
  • 241

1 Answers1

1

You can use tar for this, for example, let's you have directory '1', and you want copy something to directory '2', then:

cd 1
tar -c a.txt 3/b.txt | tar -x -C ../2

also you can use rsync it works with local paths

fghj
  • 8,185
  • 3
  • 25
  • 52