skip to Main Content

I have a lot of file with the same format (???_ideal.sdf) name and I need to rename all (???.sdf) removing form the name "ideal". For example:

Files: 
002_ideal.sdf 
ERT_ideal.sdf 
234_ideal.sdf 
sCX_idel.sdf

New Files:
002.sdf 
ERT.sdf 
234.sdf 
SCX.sdf

I thought to using a loop but I don’t know how to indicate that in the new file name should be removed "individual".

For example:

for file in ???_individual.sdf; mv $file what?

2

Answers


  1. With your shown samples, could you please try following. This will only print the rename command on terminal(for safer side, check and make sure if commands are fine and looking ok to you first before actually renaming files), to perform actual rename remove echo from following.

    for file in *_ideal.sdf
    do
       echo mv "$file" "${file/_ideal/}"
    done 
    
    Login or Signup to reply.
  2. Based on this answer you can also write it as one line with:

    rename 's/^(.*)_ideal.png/$1.png/s' **/**
    

    First parameter replaces the the _ideal.png, second one means all files.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search