LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   problematic file name (https://www.linuxquestions.org/questions/linux-general-1/problematic-file-name-482934/)

julian1972 09-12-2006 10:00 PM

problematic file name
 
Hi

I downloaded a file with a name starting with a hyphen,
and I am having a whole lot of problem dealing with it
because every command I used with it wanted to treat it
as some kind of flag. Eventually, I used Konqueror to
rename it, but the whole experience made me wonder if it
is possible to work with such a filename in a shell.
Suggestions?

Thanks.

KenJackson 09-12-2006 10:21 PM

One easy way is to add a leading "./".
Some commands have an "-f" switch that means a filename follows.
Some commands accept "--" (two dashes) as a switch to mean that no more switches follow.
If the remainder of the filename is fairly unique, you may be able to replace the '-' with a '?'.

rickh 09-12-2006 10:22 PM

Just guessing: Enclose it in quotes, or put a \ right in front of the -

Matir 09-12-2006 10:23 PM

The best way is simply to use ./-filename, as KenJackson said. Stumped me for a while too.

Wim Sturkenboom 09-12-2006 10:34 PM

If you have a look at the man pages for i.e. rm and mv, the option list can be terminated by '--'.
So mv -- -xxx.txt yyy.txt will move the file -xxx.txt to yyy.txt without problems.

[edit]bit slow[/edit]

julian1972 09-13-2006 08:58 PM

Thanks for all your help.

And fyi, quotes and \ would not work because they just protect the string from the shell, and
do not modify how the program, be it mv or rm, would parse the name.


All times are GMT -5. The time now is 08:50 AM.