-   Linux - Newbie (
-   -   Help me understand -P option for cp (

taylorkh 05-18-2010 10:05 AM

Help me understand -P option for cp
According to the man page, cp -P source DIRECTORY "append source path to DIRECTORY". I am trying to understand how this is different from cp -R source dest. For example if I have the following structure:


and I execute the following command

cp -R /mydata /mybackup

I end up with


If I execute

cp -R /mydata /mybackup

I get a message "omitting dirctory /mydata" and no files are copied. Obviously I do not understand what the -P option is for.



colucix 05-18-2010 10:29 AM


cp -P /mydata /mybackup

I get a message "omitting dirctory /mydata" and no files are copied.
I think you mean -P here (just a typo). In this case you're trying to copy a directory without the recursive -R option, hence the error "omitting directory": cp tells you it cannot copy a directory if not recursively.

Regarding the -P option, it tells to copy the parent directories of the source if they are specified on the command line (just the path, not the entire directory tree and its files). Examples: without -P:

$ cp -R /home/user/somedir/ destination/
$ ls destination

with -P:

$ cp -R -P /home/user/somedir/ destination/
$ ls destination
$ ls destination/home
$ ls destination/home/user

and with -P but without specifying the path of the source (path relative to the current working dir):

$ cp -R -P somedir/ destination/
$ ls destination

Note that the -P option has a different meaning on recent (?) versions of the cp command. For example on my OpenSuse box, with GNU coreutils-6.12, I have

-P, --no-dereference
              never follow symbolic links in SOURCE

whereas the described behavior is given by

              use full source file name under DIRECTORY

Hope this helps.

taylorkh 05-21-2010 04:32 PM

Thanks colucix! When I read you post and shifted my brain into gear with respect to "parent directory" the operation of the --parents became clear. I was going to do a little testing however, two of my file systems (750 GB and 1 TB were missing :eek:

My Ubuntu 9.10 64 bit system goes into standby as expected about 85% of the time, logs me out instead about 14% of the time and locks up the other 1% of the time. In the last situation I have no option but to power off and restart. This time it failed to mount the 1 TB hard drive and a manual mount attempt said it was already mounted or the mount point was busy. Umount said it was not mounted. Deleting the mount point and recreating it did nothing. Unplugging the hard drive and booting up caused the same problem with the 750 GB drive. Time to upgrade to 10.04 I am thinking. Booted from a CD and fsck the drives - they are OK.

Then I made a g4l snapshot of the OS partition (called it bad), restored a snapshot from February - still two AWOL file systems(?) Installed all updates and the file systems came back(??) So another snapshot to save where I had progressed to and restored the bad snapshot planning to reinstall the latest kernel and see what would happen. Booted the restored bad snapshot - before doing anything else - the file systems were back(???)

Now that I am back in operation I ran some cp commands with the -P and --parents options. It seems that -P does not do the same as --parents on Ubuntu - same as your OpenSuse box.

Thanks again,


All times are GMT -5. The time now is 11:31 AM.