Hi Guys
While programming java sometimes files with following type of name are built:
#filename#
The command
rm -rf #*
fails to delete them, while
rm -rf *#
is successful.
Why is this the case? Has someone an idea?
Thanks for your help!
Printable View
Hi Guys
While programming java sometimes files with following type of name are built:
#filename#
The command
rm -rf #*
fails to delete them, while
rm -rf *#
is successful.
Why is this the case? Has someone an idea?
Thanks for your help!
# is interpreted by the shell as "here starts a comment"
Hence rm -rf #* is actually the same as rm -rf
It you wouldnt use -f, rm would complain about a missing operand.
In the same way, rm -rf *# boils down to rm -rf *
Which is potentially dangerous, as it matches any file and directory.
You can use quotes, doublequotes or the inode numbers to remove these files.
What Irithori said... You have to mask the naked "#" somehow. One trick I've used (in addition to the suggestion to use single quotes or "\" escape characters) to help deal with files with odd characters (sometimes binary garbage) in name is to pre-pend "./" to the filename. So you can try: rm ./#file and it will work. That helps with annoying cases like filenames that start with "-" as well.
Correction:
rm -rf *# is not the same as rm -rf *
Interesting, one learns something new each day :)