Search code examples
regexlinuxbashredhatfile-rename

Removing part of the file names


I have a bunch of files like this:

file123.txt.452
file456.txt.098
file789.txt.078

How can I remove the second dot and the numbers at the end from the file names?

I tried using rename but I don’t think my regex is correct:

rename 's/txt.*/txt/' *

Solution

  • Something like:

    for f in *.txt.*; do
        g=${f%.txt.*}.txt
        mv $f $g
    done