Moving a folder, versus moving its contents (within the same partition)
GeneralThis forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!
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.
Moving a folder, versus moving its contents (within the same partition)
I only know very superficially about "how a file system works". The basic thing I know is that when you move a "file", but still within the same partition, it is not being really "physically" moved anywhere, but just having some filesystem path information changed, so it's "displayed" at a different location, changing almost only to the user's perspective.
But what about moving an entire folder (still within the same partition)? Each individual file has the full path information which got to be changed, or does it "inherit" most of the path from its container folder, so that when you move a folder, only the folder is really changed?
Most filesystems are organized in a tree-structure, IIRC, so if you move a folder only the folders information has to be connected to the new place, not its contents.
"Each individual file has the full path information which got to be changed, or does it "inherit" most of the path from its container folder, so that when you move a folder, only the folder is really changed?"
For the most part path is absolute. When you move a folder along with its contents the path changes. There some exceptions but a move is a real move to the OS and user. A subdirectory is stored the same as a file entry in the part or parts of a disk that hold it's location. Think of it as a two part process. A collection of names (file names and subdirectoies) and locations exist on the drive. That is separate from the data area. Wish I could give a real world example but I am stumped.
The term change in different file systems may be too complex. There are filesystems from decades ago to new ones and odd ones. They all act differently. Settle on one and we might know the answer.
Heh, I was thanking for the first answer when someone was typing/had just typed another, with a different answer.
I'm not actually doubting the second answer, but in my layman's mind it seems weird that the location address got to be changed in every file. Does not seem very useful, at a superficial/nearly null inspection. But perhaps that's one of those things where the intuitive alternative is simply impossible.
I get that there's the actual data in one part and their indexing in another, what we really see is a virtual, "make believe" path, while a single file may actually even be fragmented on several parts of the disk (at least in some file systems where fragmentation occurs, I guess it's quite common). What I meant that the move is somewhat "fake" is that only this representation that changed, not the actual location of the stored data. I just thought that the indexing system could be such that the "virtual paths" needed not to be absolute, in order to reduce amount of change needed.
I don't think data physically moves unless the target directory is on a different physical device (that includes a different partition within the same physical disk)
That's my understanding as well, and pretty much the only thing I'm "sure".
The doubt is in regard to whether or not the "virtual moving"/"edit on 'virtual path' information" of a folder is inherited by its contents without the contents themselves being "edited" with a new "virtual path" information. (The "contents" meaning not the actual data, but some sort of indexing/virtual representation thing)
Only the file(s) and dir(s) meta-data has to be re-written -in just the same way it would be re-written if the data itself was being moved. For each item, the new index entry is written first. If that succeeds then the old one is 'erased'. And so on for each item. In this case all 'entries' are on the same disk so it happens quickly. If data has to be moved, it takes longer. 'mv' figures out on-the-fly whether data has to really be moved or not. Of course, if a new entry fails, then nothing happens to the old data or metadata at all.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.