Re: Removing single quote from filenames (recursively)
Date: 08/17/04

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

Ben <> 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 *
        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:

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 ...
  • 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. ...
  • 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 ...
  • 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 whenever you wish just by ... Turn off the hide file extensions option ...