Find the answer to your Linux question:
Results 1 to 6 of 6
hi i ve a directory which contains many files and have a common name in the begining say like APIO_spec_min APIO_spec_min1 APIO_spec_min2 APIO_spec_typ1 ... now i would like to replace ...
  1. #1
    Just Joined!
    Join Date
    Jan 2009
    Posts
    12

    rename the files in a directory

    hi
    i ve a directory which contains many files and have a common name in the begining say like
    APIO_spec_min
    APIO_spec_min1
    APIO_spec_min2
    APIO_spec_typ1

    ...

    now i would like to replace the entire files with the name
    s2c_spec_min
    s2c_spec_min1
    s2c_spec_min2
    ....

    kindly help me out...

  2. #2
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    Try "rename". There are various different commands of that name.

  3. #3
    Just Joined!
    Join Date
    Jan 2009
    Posts
    12

    doesn t work..

    rename command doesnt work...
    or may be i dont know the usage.. could you explain that command for my files.

  4. #4
    Linux Guru
    Join Date
    Oct 2007
    Location
    Tucson AZ
    Posts
    1,939
    Make sure you are in the correct directory to run this command:

    rename APIO s2c APIO_*

  5. #5
    Just Joined!
    Join Date
    Feb 2009
    Posts
    3
    Quote Originally Posted by rajeshhariharan22 View Post
    hi
    i ve a directory which contains many files and have a common name in the begining say like
    APIO_spec_min
    APIO_spec_min1
    APIO_spec_min2
    APIO_spec_typ1

    ...

    now i would like to replace the entire files with the name
    s2c_spec_min
    s2c_spec_min1
    s2c_spec_min2
    ....

    kindly help me out...
    In bash, at the command line, in your directory:
    Code:
    for fileName in `ls -1`; \
    do echo $fileName; \
    export newFileName=`echo $fileName | sed s/APIO/s2c/`; \
    echo $newFileName; \
    mv $fileName $newFileName; \
    done
    This is from memory, but I think it is correct. The echos are only to show that something is happening. Can all be on one line, but backslashes might make it easier to read in a post.

    ¦ {Þ

  6. #6
    Linux User
    Join Date
    May 2008
    Location
    NYC, moved from KS & MO
    Posts
    251
    Command find combined with either sed or tr can handle this kind of task pretty well:

    find . -name "APIO*" | while read line; do mv $line `echo $line | tr -s 'APIO' 's2c'`; done


    find . -name "APIO*" | while read line; do mv $line `echo $line | sed 's/APIO/s2c/g'`; done

Posting Permissions

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