Re: Removing single quote from filenames (recursively)
Date: Tue, 17 Aug 2004 16:33:59 +0200 (CEST)
Ben <firstname.lastname@example.org> wrote:
> Hello all,
> I've got a bunch of files that have a single quote in them, and I'd
> like to rename them so that the quote is removed.
Supposing that you want to rename all files in a directory:
for i in *
j=$(echo "$i" | tr -d "'")
mv "$i" "$j"
If some of the filenames do not contain quotes 'mv' will complain, but
it won't hurt. Furthermore, you may want to account for special cases,
such as a file which name is all quotes, so you may need to adapt the
above code snippet a bit.
If the files to be renamed are not in the same directory you may need
to use 'find' as opposed to '*' in the for-loop above, but you get the
idea. Using 'sed' is very portable and you do not need to install other
(large and bloated) stuff that you may not have on your system, like
'zsh' or anything.
-- Protect Innovation Against Software Patents: http://swpat.ffii.org