so I wanted to change a folders name from uppercase letters to lowercase letters, so I did
mv FOLDER folder
why am I not required to make a new folder? Shouldn't I get an error like
folder does not exist
you can't copy into a folder that doesn't exist, so why can you move into one??
There is a difference between:
Where newfolder does not exist, and:
Where newfolder does not exist.
The first gives:
Whereas the second will rename oldfolder to newfolder.
In UNIX/Linux, "mv" does one of two things:
In the second case, renaming a directory doesn't create a new directory, it just changes the name of the already-existing directory.
In fact, your example does two different things, depending on whether "folder" exists as a directory already. If it does, mv works as in the first case above, i.e. moves "FOLDER" into the "folder" directory, so it's now "folder/FOLDER". On the other hand, if "folder" doesn't already exist, it just renames FOLDER.
Yes, it can be quite confusing!
In UNIX a folder is a special file.
When you ask
mv src dst
,mv
takes the filesrc
and tries to move it todst
. Several rules apply now. they are taken in order, the first one that matches is the one applied :dst
doesn't exist, it will be the destination name (regardless of the type ofsrc
)dst
already exists and is a directory, it will be considered as a path and not as the destination name. So the command will be understood asmv src dst/src
andsrc
is moved insidedst
(the final path of a isdst/src
)dst
already exists and is not a directory, it will be erased only ifsrc
is not a directory.mv
is also a renaming command. You are renaming one folder to a new name.