LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-09-2015, 05:43 AM   #1
Bogomips_
LQ Newbie
 
Registered: Jan 2014
Posts: 11

Rep: Reputation: Disabled
Question Bash Copy Update 'cp -au ' Anomaly


Code:
guest@porteus:~$ echo Update Test
Update Test
guest@porteus:~$ mkdir /tmp/src
guest@porteus:~$ touch /tmp/src/{b,c,d}
guest@porteus:~$ ls -i /tmp/src/{b,c,d}
26019 /tmp/src/b  26020 /tmp/src/c  26025 /tmp/src/d

guest@porteus:~$ ln /tmp/src/b /tmp/src/a
guest@porteus:~$ ls -i /tmp/src
26019 a  26019 b  26020 c  26025 d

guest@porteus:~$ mkdir dst
guest@porteus:~$ cp -a /tmp/src/* dst

guest@porteus:~$ ls -i dst
26002 a  26002 b  26026 c  26034 d

guest@porteus:~$ ln -f dst/c dst/a
guest@porteus:~$ ls -il dst
total 0
26026 -rw-r--r-- 2 guest guest 0 Dec  7 00:00 a
26002 -rw-r--r-- 1 guest guest 0 Dec  7 00:00 b
26026 -rw-r--r-- 2 guest guest 0 Dec  7 00:00 c
26034 -rw-r--r-- 1 guest guest 0 Dec  7 00:00 d

guest@porteus:~$ ls -il /tmp/src/
total 0
26019 -rw-r--r-- 2 guest guest 0 Dec  7 00:00 a
26019 -rw-r--r-- 2 guest guest 0 Dec  7 00:00 b
26020 -rw-r--r-- 1 guest guest 0 Dec  7 00:00 c
26025 -rw-r--r-- 1 guest guest 0 Dec  7 00:00 d

guest@porteus:~$ cp -au /tmp/src/* dst
guest@porteus:~$ ls -il dst
total 0
26026 -rw-r--r-- 3 guest guest 0 Dec  7 00:00 a
26026 -rw-r--r-- 3 guest guest 0 Dec  7 00:00 b
26026 -rw-r--r-- 3 guest guest 0 Dec  7 00:00 c
26034 -rw-r--r-- 1 guest guest 0 Dec  7 00:00 d
Expect files 'b' and 'c' to always remain unchanged.

Last edited by Bogomips_; 12-10-2015 at 05:32 AM. Reason: Bash
 
Old 12-09-2015, 06:04 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
Why do you expect that? Actually you illustrated the expected behaviour, what you think about that is not really expected.
The last cp command has no any idea about the fact: dst/a and dst/c are hard links to each other, therefore will not be able to modify it. Furthermore it will create the hard link between a and b.
 
Old 12-09-2015, 08:37 AM   #3
Bogomips_
LQ Newbie
 
Registered: Jan 2014
Posts: 11

Original Poster
Rep: Reputation: Disabled
Correctness of Implementation

^ IMHO we should not be concerning ourselves with implementation details, but rather with the correctness of the implementation.

http://manpages.ubuntu.com/manpages/...man1/cp.1.html
Code:
 -u, --update
              copy  only  when  the  SOURCE file is newer than the destination
              file or when the destination file is missing
None of the dst/* files would have been timestamped older than the src/* files, and therefore none of the dst files should have been touched.
 
Old 12-09-2015, 08:45 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
A hard link was missing, that was created again, therefore one of the files (a or b) must be linked to the other one. What is still unclear (for me) if a will be created again or b. That is not documented and I think you may have different result if (originally) you try: ln -f dst/c dst/b
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot Copy and paste from Chrome after update kujirasan Ubuntu 2 07-28-2015 11:35 PM
LXer: Anomaly Defenders Released For Linux, The Last In The Anomaly Series LXer Syndicated Linux News 0 05-31-2014 03:02 AM
Anomaly 2 is out dugan Linux - News 0 05-15-2013 10:04 PM
SVN tagging: How to update working copy from a tagged release kenneho Programming 2 01-08-2010 03:46 PM
RCU- Read Copy Update saadia47 Linux - Embedded & Single-board computer 1 02-12-2009 02:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:50 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
Open Source Consulting | Domain Registration