2

I have these two files in my home directory -

hello_newest.txt
goodbye_newest.txt

I want to rename them so that the "newest" part of the filename is removed completely, so that they would recome hello.txt and goodbye.txt

This is the command I am running -

find -name "*.txt" -exec rename 's/newest//i' {} ";"

It doesnt throw an error or do anything to the files after I run this command. I've checked out http://www.computerhope.com/unix/rename.htm and it looks like it should be working based on some of those examples that are there.

I'm sure it's something simple, but what am I missing?

user374987
  • 55
  • 1
  • 6

2 Answers2

1

Looks like it might be the version of Redhat we were on. The command -

rename _newest '' *

Seems to accomplish the same goals.

Thanks for the help.

user374987
  • 55
  • 1
  • 6
0

Different Syntax. But worked for me :

for i in *.txt; do mv "$i" "`echo $i | sed 's/_[^.]*//'`"; done

All the txt files are found using for loop and then the charecters after underscore is removed using sed.