-1

So I am trying to understand what is the significance of the -p option for the cp command.

I opened the manual of the cp command and it says -p same as --preserve=mode,ownership,time stamps.

But what is that supposed to mean>

Like I know what is ownership (Who created the file) and I know timestamps(when was the file last modified or touched) and I also know the mode( permission like 777 ).

But what is the difference between for instance:

cp file1 file2

and

cp -p file1 file2

I am supposed to create a c program that implement cp -i -p file1 file2

I know -i basically will prompt the user if file2 was already created and is about to be overwritten but for -p I have no clue.

4

enter image description hereAssume the file1 in your example was created yesterday. If you do not use the -p option, the creation date for file2 will be today and right now. If you use -p option, file2 will look like it was created yesterday. And that is just for the timestamp. If you are copying the file as someone other than the creator of the file, it will assume your identity as an owner if -p option is not there.

Please see the screen capture attached.

  • Preserving ownership works only if you happen to be running as root. – Thomas Dickey Jan 26 '16 at 0:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.