Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a directory called --pycache--, which I need to move to __pycache__. Using the mv command in the following way, gives me the listed output. How can I use the CLI to do what I want?

$ mv --pycache-- __pycache__
/bin/mv: unrecognized option '--pycache--/'
share|improve this question
add comment

2 Answers

up vote 22 down vote accepted

This is a standard issue with filenames/directories starting with less conventional symbols. Your problem is that mv is treating --pycache-- as long option name (since it starts with --, there are also short options, they start with -). Please see manpage for getopt for details about long and short options.

The standard workaround in this situation is to use an empty double dash -- before all argument, which tells the command (mv in your case, but will work with others, cp for example) to stop treating what follows as options and treat it as arguments.

Thus, your command will become:

$ mv -- --pycache--/ __pycache__

and won't fail.

share|improve this answer
7  
good answer but I think you mean -- tells the command to stop treating what follows as options and treat it as arguments, not the other way round. –  RoundTower Nov 26 '11 at 12:24
1  
I think it's more portable to prepend ./: mv ./--pycache-- __pycache__. –  Kevin Nov 26 '11 at 18:32
1  
@Kevin That works only if the argument is a file name. –  starblue Nov 26 '11 at 18:42
add comment

Your first character - is ambiguous for the mv command (or rather, it unambiguously means that an option name follows).

Try this instead:

mv ./--ppycache-- __pycache__

Source: linux.about.com

share|improve this answer
1  
+1 for alternate solution that also works if the command does not support -- –  Sverre Rabbelier Nov 26 '11 at 12:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.