How to rename files

Hi Guys,

I have to rename about 180 files in different folders in linux. For example,

abc_110117.txt
eff_110117.txt
zzz_110117.txt

After renaming the files, these files should like like

abc.txt
eff.txt
zzz.txt

I created a small script to rename the files like

ls $COMP_FILE_DIR/*.txt > $COMP_FILE_DIR/change_file_name.txt
while read line
do
FILE=$(echo $line | cut -f1 -d\_)
FILE_NAME=$(echo $FILE'.txt')
mv $line $FILE_NAME
done < $COMP_FILE_DIR/change_file_name.txt
rm $COMP_FILE_DIR/change_file_name.txt

But because of time contraints and using different folders, I have to spend too much time to rename the files.

Is there one command that I can run to rename the files.

Thanks a lot.

Naveed

Use a list of folders andn the find command:
create a file with the names of the directories
ex: call the file dirnames, put the directory names in the file using an editor or ls or whatever

mydir
/path/to/your/dir
while read dir
do
    find $dir -name '*.txt' |
    while read fname 
    do
        newname=$(fname%%_}".txt"
        mv $fname $newname
    done
done <  dirnames

TEST it first to be sure, change the mv command to an echo for example

Thanks a lot for the rely. But I wanted to use only one statement to rename the files using command line manually. I have found the command in other post.

rename _110117.txt .nav *_110117.txt

Naveed