Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Apr 2003 08:55:23 -0500
From:      "Mark Johnston" <mjohnston@skyweb.ca>
To:        "'Dave [Hawk-Systems]'" <dave@hawk-systems.com>
Cc:        freebsd-isp@freebsd.org
Subject:   Re: mv file with illegal character <- twist
Message-ID:  <002601c30b32$51aa9530$be0fa8c0@MJOHNSTON>
In-Reply-To: <DBEIKNMKGOBGNDHAAKGNMEJENAAB.dave@hawk-systems.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Dave [Hawk-Systems] wrote:
> how about this, rm du and any other commands show an error because the
> filename is a non-printable character...
> 
> ls -laB shows it as
> 
> - l\010\010\010\010
> 
> ideas?

I tried this and wound up deleting it the same way I created it:

rm `echo -e l\\\010\\\010\\\010`

I don't have much shell-fu, so this could probably be done a better
way, but it did the trick.  I'd recommend a more general fix for the
problem, though - maybe something like this:

#!/usr/bin/perl
opendir F, '.';
for $old (readdir(F)) {
        $new = $old;
        $new =~ s/([\x00-\x1f\x7f-\xff])/hex(ord($1))/e;
        rename $old, $new if $old != $new;
}

The shell is a fiddly place to be messing around with unprintables -
if you use an 8-bit clean language that implements rename() or
unlink(), your results will be more predictable.

Mark



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?002601c30b32$51aa9530$be0fa8c0>