Recently I was moving files from one directory to another on a CentOS 5.4 server and ran into an issue. When attempting to move every single file in the directory I received an error which is noted below. It took me a couple minutes but I figured out by trial and error that the issue was related to files starting with a “-”(dash) because the mv command thought that I was attempting to use a switch. The resolution is easy using “./”. Look at the below examples for more information about the error and how it was resolved.

Linux mv Command Error When Moving Files Between Directories:

[root@dev directory]# mv * /some/other/directory/
mv: invalid option -- 1
Try `mv --help' for more information.
[root@dev directory]#

As you can see above the mv command is having a problem of some sort with what it thinks is some form of “1″ option or switch. Below were the files in the directory.

List Of Files That mv Was Having An Issue Moving:

[root@dev directory]# ls
-15:28:43.txt  -15:31:12.txt
[root@dev directory]#

The above two files were the files left after moving hundreds of other files from the directory so the example was not overwhelming. As you can see both problem files start with “-” or a dash. The easiest way to get around this problem is adding a dot slash or “./” to the front of the command such as listed below.

How To mv Files That Start With A Dash:

[root@dev directory]# mv ./-15:* /some/other/directory/
[root@dev directory]#

As you notice you will no longer get the error and the files will have been moved to the new directory.

List Price: $49.99 USD
New From: $61.72 USD In Stock
Used from: $4.10 USD In Stock

List Price: $39.99 USD
New From: $20.94 USD In Stock
Used from: $0.58 USD In Stock

Tags: , , , , , , , , , , , , ,
3 Responses to “How To mv Files With A Dash: mv: invalid option — 1, Try mv –help for more information”
  1. markie_mark says:

    Using shell expansions such as “*” can be a no-no for a number of reasons such as the one you mentioned above, even more so if you don’t use the GNU versions of such commands. A more compatible maner to achieve the result could be to use “find”

    find . -type f -exec mv {} /dest;

    Or indeed looping it in a for loop

    for file in `find . -type f`; do mv…



    alex Reply:

    Hola Mark,

    what the… I was looking for you about an hour ago. #linuxpeople reunion. see you now there.

    Anyhow fair enough however however sometimes I do things that might not be so nice…. :P



  2. Doug Higby says:

    Hey thanks for this article. Sure enough, there were files that started with a dash in the directory that was giving me problems.


Leave a Reply

*Type the letter/number combination in the abvoe field before clicking submit.