Results 1 to 6 of 6
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.
...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 12-06-2012 #1Just Joined!
- Join Date
- Nov 2011
- Posts
- 7
Simple rm command on console
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!
- 12-06-2012 #2
# 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.Last edited by Irithori; 12-07-2012 at 07:40 AM.
You must always face the curtain with a bow.
- 12-07-2012 #3Just Joined!
- Join Date
- Nov 2011
- Posts
- 7
- 12-07-2012 #4Linux Newbie
- Join Date
- Jun 2012
- Location
- SF Bay area
- Posts
- 101
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.
- 12-07-2012 #5You must always face the curtain with a bow.
- 12-07-2012 #6
Correction:
rm -rf *# is not the same as rm -rf *
Interesting, one learns something new each day
You must always face the curtain with a bow.


Reply With Quote

