[PLUG] trouble deleting files
Ken Stephens
kens at cad2cam.com
Sat Dec 27 04:50:14 UTC 2008
M. Edward (Ed) Borasky wrote:
> Rich Shepard wrote:
>
>> On Fri, 26 Dec 2008, M. Edward (Ed) Borasky wrote:
>>
>>
>>>> On Fri, Dec 26, 2008 at 3:20 PM, Bill Barry <bill at billbarry.org> wrote:
>>>>
>>>>> I am deleting some old backups and I getting some errors like
>>>>>
>>> Well ... I ran into something like this and ended up having to write a
>>> Perl script to open the directory ("opendir"), search through it, and then
>>> unlink all the files with the bogus names. I couldn't figure out how to do
>>> that from the command line or a bash script -- I had to do it in Perl.
>>>
>> What happens if the rm command is followed by the file names in double
>> quotes? I know this works when there are blanks or undisplayable characters
>> in the filename, but I've no idea what the question marks might indicate.
>>
>> Rich
>>
>>
> That's the problem ... the question marks stand for characters that have
> no printable equivalent. I had to read them with Perl code and pass the
> name strings to the unlink routine to get rid of them. There may be a
> command-line routine that will convert them to hexadecimal or something,
> but the Perl thing worked before I had a chance to dig into other hacks.
>
> Now if you have the inode numbers (ls -li), there might be a way to get
> rid of them by inode number. I think I tried that, but I don't remember.
> I also think I tried "rm -i *" and saying yes for the bogus ones and
> that didn't work either for some reason. It was faster for me to do it
> in Perl. That also gave me the ability to print the file names, etc., in
> hexadecimal.
>
>
One old UNIX trick on deleting files with funky names is to use the find
command with the ls -i command. ls -i gives you the inode for the
file. You can then use the find command to locate the file using the
inode and with the -exec option of find remove it.
[me at mysystem ~]$ touch inode
[me at mysystem ~]$ ls -i inode
2907819 inode
[me at mysystem ~]$ find . -inum 2907819 -exec rm {} \;
[me at mysystem ~]$ ls -l inode
ls: cannot access inode: No such file or directory
[me at mysystem ~]$
Ken
CAD 2 CAM
More information about the PLUG
mailing list