Find the answer to your Linux question:
Results 1 to 2 of 2
Hello, I am trying to write a command to rename files and/or directories by replace non ascii alpha-numeric character. For this topic I will consider replacing space (" ") by ...
  1. #1
    ktk
    ktk is offline
    Just Joined!
    Join Date
    Sep 2009
    Posts
    1

    Unhappy find and space in file name

    Hello,

    I am trying to write a command to rename files and/or directories by replace non ascii alpha-numeric character. For this topic I will consider replacing space (" ") by underscore ("_") in filenames.

    First I wrote :
    Code:
    for i in *; do mv "$i" `echo $i | tr ' ' '_'`; done
    It works well but does not treat subdirectories...

    So I wanted to try with find :
    Code:
    find . -type f -execdir mv "{}" `echo "{}" | tr ' ' '_'` ";"
    But it does not work.

    For information:
    in a filetree like
    racine
    - sub dir
    - other one
    Code:
    find racine -type f -execdir echo `echo "{}" | tr ' ' '_'` ";"
    returns:
    sub dir
    other one
    We can see that the space have not been deleted...

    Does somebody know why ?

  2. #2
    Linux Newbie
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    109
    Hi ktk
    I am unable to help with your direct question but I thank you for your first line of code. It has helped me with a problem I have been struggling with for several weeks. If you ever solve your question please post back as many can benefit by your solution. You obviously have a lot of skill with CLI cammands. Cheers...
    Robert

Posting Permissions

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