Chapter 21 - Hardlinks
In chapter 21. LINUX FILESYSTEMS AND THE VFS
I have a small problem with understanding the part with the hard links. (the bold marked part)
On the page for "Hard and Soft Links" it´s explained as:
Hard links point to an inode. They are made by using ln without an option. Two or more files can point to the same inode (hard link). All hard linked files have to be on the same filesystem. Changing the content of a hard linked file in one place may not change it in other places.
i create a file on my desktop and hardlink it to a file in my home folder.
when i change the file in one place the other file (hardlink) is also changed and vice-versa
[email protected]:~/Desktop$ echo Test > Test [email protected]:~/Desktop$ cat Test Test [email protected]:~$ ln Desktop/Test linktest [email protected]:~$ cat linktest Test [email protected]:~$ echo test123 >> linktest [email protected]:~$ cat Desktop/Test Test test123 [email protected]:~$ echo test123 >> Desktop/Test [email protected]:~$ cat linktest Test test123 test123 [email protected]:~$ cat Desktop/Test Test test123 test123
Comments
-
I think one of the cases they may be talking about is copying files. If you have the following files and links for example:
ln link1 file1 #hard link ln -s link2 file2 #soft link
If you try to copy a file onto link1, file1 does not change. If you copy a file onto link2, file2 does change.
0 -
Thank you for your reply. i checked it again.
I don´t get it the way as its explained in the chapter. regardless of what im doing, content is changing.
Where is the mistake???Example #1
Copy a file on the sourcefile, is changing source and hardlink content.
[email protected]:~/testme$ echo source > source [email protected]:~/testme$ cat source source [email protected]:~/testme$ ln source hardlink [email protected]:~/testme$ cat source hardlink source source [email protected]:~/testme$ cp test source [email protected]:~/testme$ cat source hardlink test test
Example #2
Copy a file on the hardlink is changing source and hardlink content, too[email protected]:~/testme$ echo source > source [email protected]:~/testme$ ln source hardlink [email protected]:~/testme$ cat source hardlink source source [email protected]:~/testme$ cp test hardlink [email protected]:~/testme$ cat source hardlink test test
0 -
This is correct behaviour, this is often misunderstood. most programs should modify both instances when something is hardlinked. However, there are cases where an update is done by a different procedure; the file is copied, the update is on the copy, and the copy is then overwritten to the original location, and the link is broken. It will not happen if you just edit a file in place. For example, there is a script called
ready-for.sh
you may have run in preparation for this course (you can see it at https://training.linuxfoundation.org/cm/prep/ready-for.sh). If you run./ready-for.sh --update
, it does exactly what I am saying -- any hard links are broken.One upon a time many programs thoughtlessly broke the links when doing updates, but people tend to be more careful now and do it only by design -- we hope
1 -
Yes, i know the ready-for.sh script, used it for the ubuntu vm i use for the exercises.
If its correct behaviour than i think i have understand the topic. At the beginning i had a problem with how its explained in the chapter.
thank you
0
Categories
- 10.1K All Categories
- 35 LFX Mentorship
- 88 LFX Mentorship: Linux Kernel
- 504 Linux Foundation Boot Camps
- 279 Cloud Engineer Boot Camp
- 103 Advanced Cloud Engineer Boot Camp
- 48 DevOps Engineer Boot Camp
- 41 Cloud Native Developer Boot Camp
- 2 Express Training Courses
- 2 Express Courses - Discussion Forum
- 1.8K Training Courses
- 17 LFC110 Class Forum
- 5 LFC131 Class Forum
- 20 LFD102 Class Forum
- 148 LFD103 Class Forum
- 13 LFD121 Class Forum
- 61 LFD201 Class Forum
- LFD210 Class Forum
- 1 LFD213 Class Forum - Discontinued
- 128 LFD232 Class Forum
- 23 LFD254 Class Forum
- 569 LFD259 Class Forum
- 100 LFD272 Class Forum
- 1 LFD272-JP クラス フォーラム
- 1 LFS145 Class Forum
- 23 LFS200 Class Forum
- 739 LFS201 Class Forum
- 1 LFS201-JP クラス フォーラム
- 1 LFS203 Class Forum
- 45 LFS207 Class Forum
- 298 LFS211 Class Forum
- 53 LFS216 Class Forum
- 46 LFS241 Class Forum
- 41 LFS242 Class Forum
- 37 LFS243 Class Forum
- 10 LFS244 Class Forum
- 27 LFS250 Class Forum
- 1 LFS250-JP クラス フォーラム
- 131 LFS253 Class Forum
- 998 LFS258 Class Forum
- 10 LFS258-JP クラス フォーラム
- 87 LFS260 Class Forum
- 126 LFS261 Class Forum
- 31 LFS262 Class Forum
- 79 LFS263 Class Forum
- 15 LFS264 Class Forum
- 10 LFS266 Class Forum
- 17 LFS267 Class Forum
- 17 LFS268 Class Forum
- 21 LFS269 Class Forum
- 200 LFS272 Class Forum
- 1 LFS272-JP クラス フォーラム
- 212 LFW211 Class Forum
- 154 LFW212 Class Forum
- 899 Hardware
- 217 Drivers
- 74 I/O Devices
- 44 Monitors
- 115 Multimedia
- 208 Networking
- 101 Printers & Scanners
- 85 Storage
- 749 Linux Distributions
- 88 Debian
- 64 Fedora
- 14 Linux Mint
- 13 Mageia
- 24 openSUSE
- 133 Red Hat Enterprise
- 33 Slackware
- 13 SUSE Enterprise
- 355 Ubuntu
- 473 Linux System Administration
- 38 Cloud Computing
- 69 Command Line/Scripting
- Github systems admin projects
- 94 Linux Security
- 77 Network Management
- 108 System Management
- 49 Web Management
- 63 Mobile Computing
- 22 Android
- 27 Development
- 1.2K New to Linux
- 1.1K Getting Started with Linux
- 528 Off Topic
- 127 Introductions
- 213 Small Talk
- 20 Study Material
- 794 Programming and Development
- 262 Kernel Development
- 498 Software Development
- 923 Software
- 258 Applications
- 182 Command Line
- 2 Compiling/Installing
- 76 Games
- 316 Installation
- 54 All In Program
- 54 All In Forum
Upcoming Training
-
August 20, 2018
Kubernetes Administration (LFS458)
-
August 20, 2018
Linux System Administration (LFS301)
-
August 27, 2018
Open Source Virtualization (LFS462)
-
August 27, 2018
Linux Kernel Debugging and Security (LFD440)