[TriLUG] cp and a new fs, eg ntfs

Scott G. Hall ScottGHall at BellSouth.Net
Sat Jul 31 12:46:23 EDT 2010


'cp' in and of itself is not that complicated, and has no device (or fs)
knowledge.  'cp' is usually implemented as a built-in to each shell
rather than as a separate utility (though one is provided for other
purposes).  Given that, in several of the ksh and bash family, and in
csh, tcsh, etc, you can add the "-p" option to preserve permissions,
ownership and timestamps, and add the "-d" option to preserve hard and
soft links.

In fact, in my .bashrc (also in my .kshrc and .cshrc) I alias "cp" to
"cp -dp" for that very reason.

Beware though that not all permissions, flags and timestamps translate
across different filesystem types -- like copying from ntfs to ext2 and
back, or from nfs to ext2.  Sometimes these depend on how the filesystem
is mounted and what options are used to mount the filesystem.  You can
force umask and ownership in the mount options.

Note other alternatives as well: "cpio -p" (passthrough mode, or simply
copy mode; cpio stands for "copy I/O"), tar, rsync, dd all of which have
a simple copy component to help preserve permissions & ownership.

Joseph Mack NA3T wrote:
> I'm wondering how cp on linux works. I have ntfs-3g mounting windows disks.
> Does cp have to be ntfs-3g (or fs) aware? If I cp ntfs to ntfs, will the
> permissions (or whatever is unique to ntfs) get copied correctly? Is
> getting the permissions right part of the ntfs-3g code and cp invokes
> calls in the ntfs-3g drivers?
> 
> It's hard to imagine any other way of doing it, but I just realised that
> I don't know what happens. Otherwise the fs tools (cp, mkdir...) would
> need code for all the fs, and when a new fs came out, the fs tools would
> have to be upgraded.

-- 
Scott G. Hall
Raleigh, NC, USA
ScottGHall at BellSouth.Net



More information about the TriLUG mailing list