I don't know how I've done this but I've created somehow a folder named "-p". Now I'm trying to delete it but my buntu is thinking I'm passing -p as a paremeter.
What can I do?
Ubuntu Server 15.
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.
Sign up to join this communityI don't know how I've done this but I've created somehow a folder named "-p". Now I'm trying to delete it but my buntu is thinking I'm passing -p as a paremeter.
What can I do?
Ubuntu Server 15.
You can use --
to tell rm
(and many other commands including many shell built-ins) not to interpret any further input as command parameters, so that -p
can be interpreted correctly as an argument instead of an "unrecognised option"
rm -- -p
(This is also a good safety measure when globbing. You might have accidentally created a file called -rf
...)
--
to tell bash not to interpret any further input as command parameters" — Isn't it actually telling rm
not to interpret any further parameters as options?
– Tanner Swett
Nov 15 '16 at 0:43
--
is interpreted by rm
, not bash
. And while there is a recommendation in the SUS for tools to accept this special separator, there is no requirement to do so, and not all of them do. dd
is well known for having a radically different syntax from what we now consider to be "standard" syntax (i.e. GNU getoptlong
), for example.
– Jörg W Mittag
Nov 15 '16 at 0:58
the proper way in this case is :
rm ./-p
--
may work with some commands, and fail with others. it is not bash that interprets it, but each command separately (and some may not recognise --
as the end of options) (especially true if you ever use non gnu commands... for example if you work on some other OSs).
Taking the habit of saying ./somefileorglob
instead of just somefileorglob
is a good habit, in general.
./
to run a script in the current directory too. Whereas -- script-name
doesn't work. Plus --
is a fringe thing hard to remember.
– WinEunuuchs2Unix
Nov 15 '16 at 3:03
rm -rf "./-p"
(double quoted)
– Magno C
Nov 16 '16 at 12:36
ls -l ./*-*p* | cat -ve
may help in most cases: -v
will make cat make some characters visible (^M, for example) and combined with e
it will also mark the end of each lines with "$", which helps when the line has trailing spaces or tabs. This can help determine the name. or use "od" on the output. You can also use Tab completion: ls -ld ./-
and press TAB to let bash complete the rest (or show a selection if there are several candidates). CAREFUL: Tab, not SPACE
– Olivier Dulac
Nov 16 '16 at 18:04
delete folder strange
versuscommands with dash parameter
). – Magno C Nov 16 '16 at 12:44