Is it possible to create a directory with the name -1 in Debian
I've tried:
mkdir '-1' mkdir \-1 to no avail. Is it possible to create a directory beginning with the negative sign followed by a digit? |
i would say probably not, (at least not with the command line) with good reason, the - symbol is parsed to mean that the character following is a flag or argument, thus creating a file name that begins with (or contains a space followed by a -, such as '1 -2') would be mis-parsed by the shell, creating all sorts of problems, that being said you probably could do so in a graphical file manager, but i wouldn't recommend doing so,
imho this seems a bit like asking why you can't use a '/' in a file name (in case you are wondering, / is a directory separator and again would be mis-parsed) |
Yes it is possible - you need to add ./ in front of it:
Code:
[00:57:56](david@BlackSun)(~/xxxx)% mkdir ./-1 |
Quote:
But anyway, dive's solution is correct. "." means the current directory, so prepending it to absolute paths doesn't change them. It's actually a good idea to use "./" inside scripts, in case filenames start with a character that a command might interpret as an option. |
As mentioned, the problem is that "-" indicates an option to most commands. Quoting doesn't any good because they are removed by the shell before the command is executed, and the raw value is what's passed to it.
What you need is some way to tell the command that it's not an option, but an argument. Prefixing it with an explicit pathname is one way. Another is that most commands accept a "--" option, which tells it that there are no more options to process. Everything after that is to be treated as an argument. Some commands like grep and sed also have other options that can be used as well (-e in this case). http://mywiki.wooledge.org/BashPitfa...leading_dashes |
Why do it? You may force Linux to create a directory or file with an odd name, but there will always be the risk of things behaving badly later on. The best practice is
- start names with a letter or number - only include letters, numbers, underscore, hyphen, and dot |
Quote:
Code:
mkdir -- -1 Example: lets say you want to grep a file for the string "-v" normally "-v" will be considered the option to reverse the matching pattern, but with -- you can grep for "-v" string like this: grep -- -v file Example 2 to remove -1 direcory rmdir -- -1/ |
All times are GMT -5. The time now is 02:46 PM. |