[Problem] Mv command meet problem when file name has prefix "-"
I want to use mv command to rename from "-abc.txt" to "abc.txt". But
Eg Code:
mv '-abc.txt' abc.txt Thank you in advance. |
Renaming just the one file with rename command:
Code:
rename -abc.txt ""abc.txt -abc* |
you can use a programming language such as Ruby(1.9+), which doesn't get affected by such shell quirks
Code:
$ ruby -rfileutils -e 'Dir["-*"].each{|x|FileUtils.move(x, "/destination")}' |
Many commands use two hyphens to indicate the end of options. Try
Code:
mv -- '-abc.txt' 'abc.txt' |
Quote:
Code:
xuta@xuta-laptop:~/Public$ ruby --version ---------- Post added 04-05-11 at 09:33 AM ---------- Quote:
Thank you very much. |
You can also target the offending file by prefixing it with the full or relative path.
Code:
mv /path/to/-abc.txt abc.txt |
Quote:
Thank you so much. |
Quote:
Code:
ruby -e 'File.rename(....)' |
Good tip for the future: don't start file names with a hyphen. The shell expects names
1. to start with a letter, number, "_", or "." (hidden files). 2. to only contain letters, numbers, or the characters "_.-". No spaces or other symbols. |
All times are GMT -5. The time now is 04:50 AM. |