Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

4 Answers 4

up vote 11 down vote accepted

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.

share|improve this answer

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!

share|improve this answer

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.
share|improve this answer
    
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 '09 at 1:56

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.