Re: Renaming files using find

From: Giorgos Keramidas (keramida_at_ceid.upatras.gr)
Date: 08/31/04

  • Next message: Chris: "opiekeys and IMAP"
    Date: Tue, 31 Aug 2004 18:37:26 +0300
    To: Gerard Samuel <fbsd-questions@trini0.org>
    
    

    On 2004-08-31 11:15, Gerard Samuel <fbsd-questions@trini0.org> wrote:
    >
    > Im trying to rename a few files with the .dist extension.
    > Im trying ->
    > hivemind# find . -name '*.dist' -exec cp {} `basename {} .dist` \;
    >
    > And Im getting ->
    > cp: ./html.php.dist and ./html.php.dist are identical (not copied).
    > cp: ./horde.php.dist and ./horde.php.dist are identical (not copied).
    > cp: ./motd.php.dist and ./motd.php.dist are identical (not copied).
    > cp: ./mime_mapping.php.dist and ./mime_mapping.php.dist are identical (not copied).
    > cp: ./prefs.php.dist and ./prefs.php.dist are identical (not copied).
    > cp: ./registry.php.dist and ./registry.php.dist are identical (not copied).
    > cp: ./lang.php.dist and ./lang.php.dist are identical (not copied).
    > cp: ./mime_drivers.php.dist and ./mime_drivers.php.dist are identical (not copied).
    >
    > What is wrong with the command that I issued.

    The basename command gets expanded by the shell you use *BEFORE* find
    has a change to run.

    You can try playing tricks with escaping the backquotes, which is
    probably going to result very quickly in ugliness like \\\`foo\\\` or
    you can use find to "generate" a list of filenames which will be
    "processed" by the rest of the command-line to spit out the rename
    commands, and feed them to sh(1) for execution, i.e.:

        $ ls -l
        total 0
        -rw-rw-r-- 1 keramida wheel - 0 Aug 31 18:33 koko.dist
        -rw-rw-r-- 1 keramida wheel - 0 Aug 31 18:33 lala.dist

        $ find . -name \*.dist | \
          awk '{ printf "mv \"%s\" `basename \"%s\" .dist`\n",$0,$0; }'

        mv "./lala.dist" `basename "./lala.dist" .dist`
        mv "./koko.dist" `basename "./koko.dist" .dist`

        $ find . -name \*.dist | \
          awk '{ printf "mv \"%s\" `basename \"%s\" .dist`\n",$0,$0; }' | sh

        $ ls -l
        total 0
        -rw-rw-r-- 1 keramida wheel - 0 Aug 31 18:33 koko
        -rw-rw-r-- 1 keramida wheel - 0 Aug 31 18:33 lala

    _______________________________________________
    freebsd-questions@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-questions
    To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"


  • Next message: Chris: "opiekeys and IMAP"

    Relevant Pages

    • Re: Great SWT Program
      ... a good tutorial on Unix CLI tools? ... command there, ... then rename everything in the search scope with the CLI, ... I'd have to boot up a Windows system and try stuff, ...
      (comp.lang.java.programmer)
    • Re: How To Make index.shtml As A Home Page?
      ... is the correct command, but will only be effective if AllowOverride All ... overridden (provided AllowOverride is set) using .htaccess as you have done. ... > DirectoryIndex index.shtml index.html index.htm index.php ... you should be able to open your online web in FrontPage and rename ...
      (microsoft.public.frontpage.client)
    • Re: Cant Rename a File Using WinXP Command Prompt!!!
      ... It needs to be given a shorter name so that it can be ... I cannot rename it using the Command Prompt and the ... The old filename in question contains the following symbols as ...
      (microsoft.public.windowsxp.help_and_support)
    • =?UTF-8?Q?Re:_The_rename_command=E2=80=A6?=
      ... the command would be much more efficient if find was only ... *every* file gets passed to rename. ... the Swedish characters gets "distorted" anyway): ... understanding English in manuals etc). ...
      (Ubuntu)
    • Re: The rename =?windows-1252?Q?command=85?=
      ... From the very beginning of Linux the Windows users had to ... learn that rename is not part of the commands. ... When first starting to use computers, if we do not count the very first ... I accidently found that rename command, ...
      (Ubuntu)