Skip to content
Advertisement

SED : Remove last four characters from filename

I had list of files in the folder named test_images as below

JavaScript

i want to rename all file by removing last four characters from each of them as

JavaScript

How can i do it using sed ?

Any suggestion will be appreciated.

Thanks in advance 🙂

Advertisement

Answer

if your file names don’t have spaces, you can: (under your test_images dir)

JavaScript

to check the generated mv command. If it is ok, add |sh to the above command to do the actual renaming.

If your filenames have spaces, you need add quotes:

JavaScript

This is a quick and dirty solution, since working with ls result is not good practice.

update: add “how to” example:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement