mv file with illegal character <- twist

Mark Johnston mjohnston at
Fri Apr 25 06:55:10 PDT 2003

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:

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.


More information about the freebsd-isp mailing list