mv $file $dirwill move the a file to the named directory ... if the named directory exists. If not, it will treat the "directory" name as a file, and move or rename the file to that directory. In other words, the command:
for i in precious* do mv $i dir donewill save all the files in the directory "dir" if "dir" is a directory, or rename each file as "dir" (all but the last will be lost) if "dir" is not a directory.
Therefore:
make sure the destination is unambiguously a directory reference:
for i in precious* do mv $i dir/ donewill fail, loudly and obviously, if "dir" is not already a directory. This form is preferable to using "dir/$i" as the target for several reasons:
If I do this:
$ touch foo bar $ mv foo bar bazthen GNU mv complains about the last name not being a directory.
Contributors: PaulChisholm, BillTrost