Need help renaming bulk file extentions

Hello,

I am trying to rename bulk files however i dont think the rename/mv command is giong to help me here. here is a quick snapshot of the files I need to rename:

75008040 -rw-r----- 1 root root 8716 May 8 05:00 10.9.144.2
75008041 -rw-r----- 1 root root 11700 May 8 05:00 10.9.160.2
75008042 -rw-r----- 1 root root 9019 May 8 05:00 10.9.16.2
75008043 -rw-r----- 1 root root 10011 May 8 05:00 10.9.176.2

I would like the files to look lik this when done:

75008040 -rw-r----- 1 root root 8716 May 8 05:00 10.9.144.2.txt
75008041 -rw-r----- 1 root root 11700 May 8 05:00 10.9.160.2.txt
75008042 -rw-r----- 1 root root 9019 May 8 05:00 10.9.16.2.txt
75008043 -rw-r----- 1 root root 10011 May 8 05:00 10.9.176.2.txt

I think the issues is that thre are many dots int he filename and mv/rename doest understand that. Not suree what I can do. My goal is to figure out he cmmand and run a cron job to do this daily as new files are writin. Thanks in advance for any suggestions.

Simply use a loop, quote, and * wildcard will expand to every filename starting with 10:

for i in 10.*; do mv "$i" "$i".txt; done

Hi there,

I'm not close to my Linux Box, but I think the dots has no problem :

for i in `ls -l | awk '{ print $NF}'`
do
mv $i $i".txt"
done

Check on dummy files before, my code isn't checked.:smiley:

thanks for the quick response but I am a linux newb. Where would I write this code?

The above two solution would add .txt to the file names.

But, as Jallan mentioned - he/she would be running a cron job everyday to add .txt to the new files add to that directory.

The above codes will also add .txt to the files that already have .txt extension.

So I guess first is to get file names that do no have .txt extension and then update them.

Actually my cron job would delete all files first and add the new files then add .txt. But im not sure how to write this code in a cron job:(

Check out the below post on cron and crontab:

Lets see what kind of questions you have after that..

actually my question is not on crantab. Im asking where to I type 'for i in 10.*; do mv "$i" "$i".txt;'?

My quesiton is not about cron... Im asking where to I type for i in 10.*; do mv "$i" "$i".txt;? I tried typing it at eh commoand line but that does not work.

ACtully my question is where do I type 'for i in 10.*; do mv "$i" "$i".txt; done'? I does not work on the command line.

You should write those commands in one script file and then run this file in a cron.

# delete existing files
rm /your_dir/10.*
# create/add new files ...
...
# rename new files
for i in `ls /your_dir/10.*`
do
   mv ${i} ${i}.txt
done