• Home »
  • Errors »
  • How To mv Files With A Dash: mv: invalid option — 1, Try mv –help for more information

How To mv Files With A Dash: mv: invalid option — 1, Try mv –help for more information

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: $123.31 USD In Stock
Used from: $10.11 USD In Stock


List Price: $39.99 USD
New From: $15.95 USD In Stock
Used from: $0.01 USD In Stock

Share