Tuesday, May 7, 2024
 Popular · Latest · Hot · Upcoming
22
rated 0 times [  22] [ 0]  / answers: 1 / hits: 3045  / 2 Years ago, thu, june 30, 2022, 12:38:27

How does linux handle a move command under the hood?



Let's say I move my home dir



/home/me


and I move this into another directory



/home/foo/me


How are all the files and directories paths under me changed? I know my Desktop dir under me is now /home/foo/me/Desktop as well as Documents /home/foo/me/Documents but does the file system explicitly update every path under me to to reflect the change? That doesn't sound very efficient and it's probably not this.



Where can I get more information on this?


More From » filesystem

 Answers
1

To understand how it move folders you may need to understand a bit about file system under linux. Every files and folders are stored as part of a data structure called an "inode". Each file has an inode number, so does folders.



To view the inode of your folder, use the command ls -ial foldername. The first column shows the inode number of the file. For each folder there are two unique names . and .., representing the directory of its own, and the parent directory respectively.



You can try doing an experiment to move a directory (say, /home/me/source) with sub-directories and files to another directory (e.g. /home/me/somewhere/else). The inode number of /home/me/source and all its contents remains the same before and after moving. The only difference is the inode number of .., which originally shares the inode number of /home/me and now becomes the inode number of /home/me/somewhere/else. In simple wording, Linux update the link to directory source and then it's done.



The contents on the hard disk are not modified anyway, only the inode index is updated when the folder is moved. This is, of course, not the case if you move the folder to a different physical location.


[#26540] Friday, July 1, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ditery

Total Points: 9
Total Questions: 116
Total Answers: 119

Location: Grenada
Member since Sun, Dec 20, 2020
3 Years ago
;