In bash, I want to delete files starting with a
#. I tried
rm #*, but got message:
rm: missing operand.
So how to achieve this?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
The octothorpe (
#), or pound sign, is a comment character, described in the POSIX grammar here as saying:
If the current character is a '#', it and all subsequent characters up to, but excluding, the next <newline> shall be discarded as a comment. The <newline> that ends the line is not considered part of the comment.
So you need to quote or escape the pound sign so that it is not interpreted as a comment:
# starts a comment, it only does so at the start of a word. So prefixing a path, like
./ for current directory, also works to disable it.
./ is also one of the two ways to prevent file names starting with a dash
-like-this) being interpreted as options to the command.
If your shell is
bash, you can disable the use of
# as a comment character in an interactive shell with
shopt -u interactive_comments
With this shell option cleared,
should work as you initially expected it, without the need to escape the
depending on the shell setup you might use
or if it is a special character interpreted and displayed as # then