Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.