[SOLVED] Is it possible to create a directory with the name -1 in Debian
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233
Rep:
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)
Quoting won't work because it's the mkdir command that parses "-" options, not the shell.
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).
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
to no avail. Is it possible to create a directory beginning with the negative sign followed by a digit?
You can create a -1 directory with this
Code:
mkdir -- -1
A double dash (--) is used in bash built-in commands and many other commands to signify the end of command options, after which only positional parameters are accepted.
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/
Last edited by RedNeck-LQ; 11-23-2011 at 10:31 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.