2

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??

4 Answers 4

12

There is a difference between:

mv oldfolder/* newfolder

Where newfolder does not exist, and:

mv oldfolder newfolder

Where newfolder does not exist.

The first gives:

mv: target `newfolder' is not a directory

Whereas the second will rename oldfolder to newfolder.

10

In UNIX/Linux, "mv" does one of two things:

  1. Moves a file or directory from its current location (in one directory) to a new location (in a different directory).
  2. Renames the file or directory, without moving it to a new location.

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!

0

In UNIX a folder is a special file.

When you ask mv src dst, mv takes the file src and tries to move it to dst. Several rules apply now. they are taken in order, the first one that matches is the one applied :

  1. If dst doesn't exist, it will be the destination name (regardless of the type of src)
  2. if 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 as mv src dst/src and src is moved inside dst (the final path of a is dst/src)
  3. if dst already exists and is not a directory, it will be erased only if src is not a directory.
1
  • Note that by "a folder is a special file", it doesn't mean the type of "special file" that is created by mknod. It just means that folders (which are usually called directories in UNIX) are treated differently from files by "mv" and other commands.
    – TimB
    May 8, 2009 at 1:56
0

mv is also a renaming command. You are renaming one folder to a new name.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .