Joe Borzellino

Q: A better way to delete a file with name ~$detritus.docx ?

I was wondering if anyone knows how to conveniently delete the Office temp files that have names like ~$detritus.docx using the terminal. I know how to delete the file using the inode, but it would be nice to be able to do this with one quick command. The inode removal goes something like:

 

ls -il 

find . -inum [inode-number] -exec rm -i {} \;


Is there another more convenient way?


Thanks



Mac Pro, OS X Yosemite (10.10.5)

Posted on Aug 21, 2015 9:22 AM

Close

Q: A better way to delete a file with name ~$detritus.docx ?

  • All replies
  • Helpful answers

  • by rccharles,Solvedanswer

    rccharles rccharles Aug 21, 2015 10:45 AM in response to Joe Borzellino
    Level 6 (8,516 points)
    Classic Mac OS
    Aug 21, 2015 10:45 AM in response to Joe Borzellino
    mac $ touch \~\$detritus.docx
    mac $ ls -l
    total 0
    -rw-r--r--  1 mac  staff     0B Aug 21 13:37 ~$detritus.docx
    mac $ rm \~\$detritus.docx
    remove ~$detritus.docx? y
    mac $ ls
    mac $ touch '~$detritus.docx'
    mac $ ls -l
    total 0
    -rw-r--r--  1 mac  staff     0B Aug 21 13:38 ~$detritus.docx
    mac $ rm  '~$detritus.docx'
    remove ~$detritus.docx? y
    mac $ ls -l
    mac $
    
    
    

     

    Would the backslash \ or the single quote ' be helpful?

     

    $detritus is the form of a bash  variable.  You need to escape the $ to prevent  bash from seeing the $ as the start of a variable.

     

    I've escaped the ~ out of principle because of it's association with one's home directory.

     

    R

    PS.  I have an alias for the rm command to add in the -i.