Is there a variant of the "cp -a" command that avoids copying from other filesystems?

6,231

On a machine with the GNU Coreutils (most Linux distros), the cp command has -x.

From cp man page:

-x, --one-file-system
Share:
6,231

Related videos on Youtube

Cerber
Author by

Cerber

Updated on September 18, 2022

Comments

  • Cerber
    Cerber almost 2 years

    Let's say I have a directory /data/something with the following subdirs:

    /data/something/iowa
    /data/something/wyoming
    /data/something/burkinafaso
    /data/something/slovenia
    

    All four subdirs have content. burkinafaso and slovenia are mount points; iowa and wyoming are not. I want to copy the directory structure in such a way that iowa and wyoming get copied recursively with all their subtrees, but burkinafaso and slovenia are copied as empty. cp doesn't seem to have such a switch, unlike du -x and find -xdev. What's the best way to do what I want?

    • Gilles 'SO- stop being evil'
      Gilles 'SO- stop being evil' almost 9 years
      What strange system do you have where du has a -x option but cp doesn't?
    • Cerber
      Cerber almost 9 years
      I am sorry. I DO know how to use a manpage, but somehow managed to miss the -x switch in there.