How do you escape “-” in a command in the Shell (Zsh)? [on hold]
I am trying to rename a file named "-a" to "a" using the command line (zsh shell). I have tried the following
mv -a "a"
mv '-a' "a"
mv "-a" "a"
but got
mv: illegal option -- a
usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory
each time. Is there a way to escape "-a" or any other command option in the shell?
command-line bash zsh
New contributor
Deepak Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
put on hold as off-topic by Terrance, Pilot6, Florian Diesch, dessert, N0rbert 4 hours ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – Terrance, Pilot6, Florian Diesch, dessert, N0rbert
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I am trying to rename a file named "-a" to "a" using the command line (zsh shell). I have tried the following
mv -a "a"
mv '-a' "a"
mv "-a" "a"
but got
mv: illegal option -- a
usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory
each time. Is there a way to escape "-a" or any other command option in the shell?
command-line bash zsh
New contributor
Deepak Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
put on hold as off-topic by Terrance, Pilot6, Florian Diesch, dessert, N0rbert 4 hours ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – Terrance, Pilot6, Florian Diesch, dessert, N0rbert
If this question can be reworded to fit the rules in the help center, please edit the question.
1
How is this question related to Ubuntu?
– Pilot6
5 hours ago
Just updated the question
– Deepak Kumar
5 hours ago
The question is off-topic here and will be closed soon.
– Pilot6
5 hours ago
Why cat, grep and other commands can't understand files starting with minus sign?
– steeldriver
5 hours ago
I believe that the comments above are suggesting that this should be posted in unix.stackexchange.com instead of on this site (if you were wondering where else you could go for help)
– Jeff
5 hours ago
add a comment |
I am trying to rename a file named "-a" to "a" using the command line (zsh shell). I have tried the following
mv -a "a"
mv '-a' "a"
mv "-a" "a"
but got
mv: illegal option -- a
usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory
each time. Is there a way to escape "-a" or any other command option in the shell?
command-line bash zsh
New contributor
Deepak Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I am trying to rename a file named "-a" to "a" using the command line (zsh shell). I have tried the following
mv -a "a"
mv '-a' "a"
mv "-a" "a"
but got
mv: illegal option -- a
usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory
each time. Is there a way to escape "-a" or any other command option in the shell?
command-line bash zsh
command-line bash zsh
New contributor
Deepak Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Deepak Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 5 hours ago
Deepak Kumar
New contributor
Deepak Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 5 hours ago
Deepak KumarDeepak Kumar
62
62
New contributor
Deepak Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Deepak Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Deepak Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
put on hold as off-topic by Terrance, Pilot6, Florian Diesch, dessert, N0rbert 4 hours ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – Terrance, Pilot6, Florian Diesch, dessert, N0rbert
If this question can be reworded to fit the rules in the help center, please edit the question.
put on hold as off-topic by Terrance, Pilot6, Florian Diesch, dessert, N0rbert 4 hours ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – Terrance, Pilot6, Florian Diesch, dessert, N0rbert
If this question can be reworded to fit the rules in the help center, please edit the question.
1
How is this question related to Ubuntu?
– Pilot6
5 hours ago
Just updated the question
– Deepak Kumar
5 hours ago
The question is off-topic here and will be closed soon.
– Pilot6
5 hours ago
Why cat, grep and other commands can't understand files starting with minus sign?
– steeldriver
5 hours ago
I believe that the comments above are suggesting that this should be posted in unix.stackexchange.com instead of on this site (if you were wondering where else you could go for help)
– Jeff
5 hours ago
add a comment |
1
How is this question related to Ubuntu?
– Pilot6
5 hours ago
Just updated the question
– Deepak Kumar
5 hours ago
The question is off-topic here and will be closed soon.
– Pilot6
5 hours ago
Why cat, grep and other commands can't understand files starting with minus sign?
– steeldriver
5 hours ago
I believe that the comments above are suggesting that this should be posted in unix.stackexchange.com instead of on this site (if you were wondering where else you could go for help)
– Jeff
5 hours ago
1
1
How is this question related to Ubuntu?
– Pilot6
5 hours ago
How is this question related to Ubuntu?
– Pilot6
5 hours ago
Just updated the question
– Deepak Kumar
5 hours ago
Just updated the question
– Deepak Kumar
5 hours ago
The question is off-topic here and will be closed soon.
– Pilot6
5 hours ago
The question is off-topic here and will be closed soon.
– Pilot6
5 hours ago
Why cat, grep and other commands can't understand files starting with minus sign?
– steeldriver
5 hours ago
Why cat, grep and other commands can't understand files starting with minus sign?
– steeldriver
5 hours ago
I believe that the comments above are suggesting that this should be posted in unix.stackexchange.com instead of on this site (if you were wondering where else you could go for help)
– Jeff
5 hours ago
I believe that the comments above are suggesting that this should be posted in unix.stackexchange.com instead of on this site (if you were wondering where else you could go for help)
– Jeff
5 hours ago
add a comment |
2 Answers
2
active
oldest
votes
When you need to specify a file name that starts with a dash as argument to a command, which might interpret it as option instead, you can write the absolute or explicit relative path to the file instead:
mv /path/to/-a a
mv ./-a a
Alternatively some (not all) commands support -- as separator between options and positional arguments. This depends on the specific command you use though.
mv -- -a a
add a comment |
mv -- -a a
The '--' tells the shell that what follows after this is not an option to the command.
All your variants give, after the evaluation of quotes and backslash, the command mv -a a so you are told that the option '-a' is not a valid option to the mv command and that you should give a target operand.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
When you need to specify a file name that starts with a dash as argument to a command, which might interpret it as option instead, you can write the absolute or explicit relative path to the file instead:
mv /path/to/-a a
mv ./-a a
Alternatively some (not all) commands support -- as separator between options and positional arguments. This depends on the specific command you use though.
mv -- -a a
add a comment |
When you need to specify a file name that starts with a dash as argument to a command, which might interpret it as option instead, you can write the absolute or explicit relative path to the file instead:
mv /path/to/-a a
mv ./-a a
Alternatively some (not all) commands support -- as separator between options and positional arguments. This depends on the specific command you use though.
mv -- -a a
add a comment |
When you need to specify a file name that starts with a dash as argument to a command, which might interpret it as option instead, you can write the absolute or explicit relative path to the file instead:
mv /path/to/-a a
mv ./-a a
Alternatively some (not all) commands support -- as separator between options and positional arguments. This depends on the specific command you use though.
mv -- -a a
When you need to specify a file name that starts with a dash as argument to a command, which might interpret it as option instead, you can write the absolute or explicit relative path to the file instead:
mv /path/to/-a a
mv ./-a a
Alternatively some (not all) commands support -- as separator between options and positional arguments. This depends on the specific command you use though.
mv -- -a a
answered 5 hours ago
Byte CommanderByte Commander
65.1k27178300
65.1k27178300
add a comment |
add a comment |
mv -- -a a
The '--' tells the shell that what follows after this is not an option to the command.
All your variants give, after the evaluation of quotes and backslash, the command mv -a a so you are told that the option '-a' is not a valid option to the mv command and that you should give a target operand.
add a comment |
mv -- -a a
The '--' tells the shell that what follows after this is not an option to the command.
All your variants give, after the evaluation of quotes and backslash, the command mv -a a so you are told that the option '-a' is not a valid option to the mv command and that you should give a target operand.
add a comment |
mv -- -a a
The '--' tells the shell that what follows after this is not an option to the command.
All your variants give, after the evaluation of quotes and backslash, the command mv -a a so you are told that the option '-a' is not a valid option to the mv command and that you should give a target operand.
mv -- -a a
The '--' tells the shell that what follows after this is not an option to the command.
All your variants give, after the evaluation of quotes and backslash, the command mv -a a so you are told that the option '-a' is not a valid option to the mv command and that you should give a target operand.
edited 5 hours ago
answered 5 hours ago
mucluxmuclux
2,3141725
2,3141725
add a comment |
add a comment |
1
How is this question related to Ubuntu?
– Pilot6
5 hours ago
Just updated the question
– Deepak Kumar
5 hours ago
The question is off-topic here and will be closed soon.
– Pilot6
5 hours ago
Why cat, grep and other commands can't understand files starting with minus sign?
– steeldriver
5 hours ago
I believe that the comments above are suggesting that this should be posted in unix.stackexchange.com instead of on this site (if you were wondering where else you could go for help)
– Jeff
5 hours ago