Re: Removing single quote from filenames (recursively)

carlos_at_linux.it
Date: 08/17/04


Date: Tue, 17 Aug 2004 16:33:59 +0200 (CEST)

Ben <bbkennedy00@yahoo.com> 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:

    cd target_directory

    for i in *
    do
        j=$(echo "$i" | tr -d "'")
        mv "$i" "$j"
    done

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.

Carlo

-- 
Protect Innovation Against Software Patents: http://swpat.ffii.org


Relevant Pages

  • Re: Erase command generating "File Does not Exist" error on valid
    ... Problem is I'm not there and the program that does this can't rename the ... Asking some of the users to remove the space at the begining of a file ... I think I may end up having to call a Windows API, ... >> or put quotes around the entire file name and this is not a bug ...
    (microsoft.public.fox.programmer.exchange)
  • RE: Error code [Error number: 0x80072EE7
    ... Type in "net stop WuAuServ" (without the quotes) and press Enter. ... Please look at the cmd window and make sure it says that it was ... successfully stopped before we try to rename the folder. ...
    (microsoft.public.windowsupdate)
  • Re: launch a .py file from a batch file
    ... That's of course after you rename your script to a pyw extension. ... With quotes it just opens a console and does nothing (does not launch the ...
    (comp.lang.python)
  • Re: Sava a test file in java
    ... > Can I save a file in java? ... Try it again using quotes around the file name. ... Or you can just rename the file whatever.java whenever you wish just by ... Turn off the hide file extensions option ...
    (comp.lang.java.help)