Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

Why not "mv -r" in Linux bash? [closed]

Writer Matthew Martinez

Well, I know you have to use -r with cp and rm when dealing with directories. It makes this job recursively (meaning it coping and removing all starting with things inside). But why you dont do "mv -r" when moving / renaming directories?

1

2 Answers

Directories are just collections of pointers to locations of files on the filesystem. When you move a directory you are updating the file pointers of the new and old parents to contain/remove the one you moved. Thus, child file pointers inside do not require recursive action as none of the pointer locations have actually changed for them.

EDIT: I've just found a much more detailed answer on Unix & Linux StackExchange that will help explain this further.

For every move, new location is needed. If one wants to move all files under directory alongwith the directory, just move the directory which is recursive.

1