Find the answer to your Linux question:
Results 1 to 2 of 2
I have a mass of directories called */small I need to rename them all to */web I was thinking of find . -type d -name 'small' -exec mv {} "${{}//small/Web}" ...
  1. #1
    Just Joined!
    Join Date
    Dec 2008
    Posts
    19

    [SOLVED] String replacement on command line - help!

    I have a mass of directories called */small

    I need to rename them all to */web

    I was thinking of

    find . -type d -name 'small' -exec mv {} "${{}//small/Web}" \;

    This obviously won't work, but I obviously need to repeat the {} somehow in the second mv argument so I can do the replacement operation on the pathname.

    It would also be nice if I could specify that the text 'small' that I want to replace is only replaced where it is at the end of the pathname and not embedded in another directory name higher up the directory tree.

    Does that make sense?

    Steve

  2. #2
    Just Joined!
    Join Date
    Dec 2008
    Posts
    19
    Sorry - Found the answer

    find . -type d | while read file; do echo mv "$file" "${file/%small/Web}"; done



    Now to read up on 'while'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...