Rename multiple files by cutting first part , the end or in middle of name under Linux – part 001.

You can see the images I make with Screenshot application and is named like :

When you want to rename multiple files recursively is very good to know how is finally format name.

It’s tree way to deal with this issue.

First you can cut the first part , the end or in middle of name.

Let cut first part in the named files. In this example I will remove : Screenshot – 10272013 – .

The next command will cut first 24 letters from the name of files.

Let’s see the output of this command:

Now I will cut the last 4 letters from the names of the files:

… and output will be :

Now you don’t use in command this:

… because you dont have now the .png in your names of files.

When you want to rename file in middle of name the you need something new.

Using the sed command to solve this issue:

You can see I change somethig from :

in this :

“$(echo $my_file | sed ‘s/ AM/ PM/g’)”

This will change the second from args of mv command into you want.

In this case will replace ‘ AM’ with ‘ PM’…

Sed also can change the special characters… Let’s remove the colon : with nothing.

… and the result of this command:

admin

born 1976, Falticeni , Suceava , Romania
Posted in All, Bash, Commands, Linux. Tagged with , , , , .