If I wanted to stay on the same file system, couldn't I just specify an output path for the same file system?
Or is it to prevent accidentally leaving the current file system?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityIt limits where files are copied from, not where they’re copied to. It’s useful with recursive copies, to control how cp
descends into subdirectories. Thus
cp -xr / blah
will only copy the root file system, not any of the other file systems mounted.
See the cp -x
documentation (although its distinction is subtle).
/mnt
is only a human convention sometimes enforced by a distro's setup but not a requirement of the OS. I sometimes have network filesystems mounted under /var/somewebsite/www/sessions
to implement load balancing web servers
Nov 29, 2018 at 15:00
--exclude
options to manually block each of them. Very useful with rsync.
/dev
, /proc
, /sys
etc. which you typically don’t want to read “en masse”.
Nov 29, 2018 at 15:09
The -x
flag to cp
is a GNU extension. When copying a single file, this option will have no effect, but when copying a whole file hierarchy, the -x
option prevents the copying of files and directories that do not live on the same filesystem as the original source.
For example, on a filesystem with mount points at /usr
and /usr/local
, using cp -xR /usr /some-dest
would not copy the hierarchy under /usr/local
.
There are other utilities with an -x
option with similar semantics, such as du
and find
(the flag is called -xdev
for find
), and rsync
.
-i
: "why not just specify a destination that doesn't exist"?