LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-18-2010, 10:05 AM   #1
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 1,389

Rep: Reputation: 101Reputation: 101
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:

/mydata/OpenOffice/(files)
/mydata/music/(files)
/mydata/other/(files)

and I execute the following command

cp -R /mydata /mybackup

I end up with

/mybackup/OpenOffice/(files)
/mybackup/music/(files)
/mybackup/other/(files)

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.

TIA,

Ken
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 05-18-2010, 10:29 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
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:
Code:
$ cp -R /home/user/somedir/ destination/
$ ls destination
somedir
with -P:
Code:
$ cp -R -P /home/user/somedir/ destination/
$ ls destination
home
$ ls destination/home
user
$ ls destination/home/user
somedir
and with -P but without specifying the path of the source (path relative to the current working dir):
Code:
$ cp -R -P somedir/ destination/
$ ls destination
somedir
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
Code:
-P, --no-dereference
              never follow symbolic links in SOURCE
whereas the described behavior is given by
Code:
--parents
              use full source file name under DIRECTORY
Hope this helps.
 
2 members found this post helpful.
Old 05-21-2010, 04:32 PM   #3
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 1,389

Original Poster
Rep: Reputation: 101Reputation: 101
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

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,

Ken
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
trying to understand top command -H option connecticket Linux - Newbie 1 06-12-2009 01:46 AM
Where is the screensaver option, and where is the sound option? Cinematography SUSE / openSUSE 1 06-20-2008 06:30 PM
understand -w option with grep geeyathink Programming 5 02-21-2008 05:17 AM
Passwd prompt option for "sysdba" option in Oracle shipon_97 Linux - Security 0 09-02-2007 03:17 AM
rpm have --nodeps option with dpkg is such an option available deepclutch Debian 2 03-26-2006 10:49 PM


All times are GMT -5. The time now is 04:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration