Linux Box Admin
Trusted Remote Administration
logo

Tilde
What's new
Articles
Micro HowTos
About
Contact







Index arrow Micro HowTos

index of all micro how-tos
arrow Userland

Delete files with bad names
(4 votes)
Wednesday, 07 March 2007
   
    Delete files with bad names    
     
       
 
If a file with a bad name gets accidentally created, such as a name that begins with "-", it can't be deleted with a normal rm command. Use the "--" option to tell rm that no more options follow, then it can delete the file.

To delete a file whose file name begins with "-":

rm -- -bad-file-name
Or
rm ./-bad-file-name

To delete a file with non-printable characters in the name:

Use shell wildcards, "?" for one character and "*" for zero or more characters. For example, if the file name "bad file name" can't be deleted, one of the spaces may in fact contain a hex value. Try:

rm bad?file?name

caution: use echo bad?file?name first to make sure you are not matching more files than you think with wildcards before deleting them.

   
       
         
 



Copyright © 2006,2007 Linux Box Admin.

 
My NHL fan blog