LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   rename dir with dashes in name (https://www.linuxquestions.org/questions/linux-newbie-8/rename-dir-with-dashes-in-name-601195/)

zeeple 11-20-2007 01:42 PM

rename dir with dashes in name
 
I recently had to unzip a mail archive and one of the users had a mail folder called:

---------Archive

They obviously put all the dashes to move it to the top of some tree, or maybe to make it stand out more. Regardless, I cannot get into it now:

[joe@mail1 inbox]# cd --------Archive
-bash: cd: --: invalid option
cd: usage: cd [-L|-P] [dir]
[joe@mail1 inbox]# cd '--------Archive'/
-bash: cd: --: invalid option
cd: usage: cd [-L|-P] [dir]
[joe@mail1 inbox]# cd "--------Archive"/
-bash: cd: --: invalid option
cd: usage: cd [-L|-P] [dir]

Notice that single quotes and double quotes yield the same result. Other operations (rm mv) result in the same. Any suggestions?

zeeple 11-20-2007 01:48 PM

solved
 
The answer was simple:

cd ./--------Archive

was what worked ;)

Poetics 11-20-2007 01:49 PM

You can use "--" as an argument to say that you will not be using any more flags. Thus it will not interpolate any of the dashes as additional flags. That, or you can escape them all.

$ cd -- "-----stuff/"
$ rm -rf -- "-----stuff/"

et cetera

druuna 11-20-2007 01:51 PM

Hi,

Try this:

cd -- --------Archive

The -- tells cd that all after it is part of the directory name.

To rename the ------Archive directory: mv -- ------Archive/ Archive

To remove it: m -rf -- ------Archive

Hope this helps

PS: To create one: mkdir -- ------Archive ;)

zeeple 11-20-2007 01:57 PM

Excellent suggestions! Thanks everyone for the contribution!


All times are GMT -5. The time now is 01:57 AM.