Skip to main content
added 326 characters in body
Source Link
Stéphane Chazelas
  • 587.9k
  • 96
  • 1.1k
  • 1.7k

With pax, to copy . into subdir/tmp, skipping subdir/tmp:

mkdir -p subdir/tmp && pax -rws'|^\./subdir/tmp/.*||' . subdir/tmp 

Alternatively, you could do something like:

mkdir -p subdir/tmp/subdir && ln -s tmp subdir/tmp/subdir/tmp && cp -a . subdir/tmp 

subdir/tmp/subdir/tmp is then a symlink to itself, to cp won't be able to create anything under it. You can replace it with an empty directory afterwards if you want.

With pax, to copy . into subdir/tmp, skipping subdir/tmp:

mkdir -p subdir/tmp && pax -rws'|^\./subdir/tmp/.*||' . subdir/tmp 

With pax, to copy . into subdir/tmp, skipping subdir/tmp:

mkdir -p subdir/tmp && pax -rws'|^\./subdir/tmp/.*||' . subdir/tmp 

Alternatively, you could do something like:

mkdir -p subdir/tmp/subdir && ln -s tmp subdir/tmp/subdir/tmp && cp -a . subdir/tmp 

subdir/tmp/subdir/tmp is then a symlink to itself, to cp won't be able to create anything under it. You can replace it with an empty directory afterwards if you want.

Source Link
Stéphane Chazelas
  • 587.9k
  • 96
  • 1.1k
  • 1.7k

With pax, to copy . into subdir/tmp, skipping subdir/tmp:

mkdir -p subdir/tmp && pax -rws'|^\./subdir/tmp/.*||' . subdir/tmp