Home Linux Community Forums Software Command Line rename a range of files using one-line command

rename a range of files using one-line command

Link to this post 16 Aug 09

Hi, all

I have a range of files in a certain dir, like this,

$ touch file[123456]
$ ls
file1 file2 file3 file4 file5 file6

now, how could rename them, and add a prefix to each file? for example, add a 'pre-' prefix, as following,


Thanks in advance. :cheer:


Link to this post 16 Aug 09

for files in filename* ; do new="prefix_$files" ; echo "$files $new" ; done

you don't even need the new="prefix_files";

you can
for files in filename* ; do mv $files pre_$files ; done

and make it even shorter

root@msu:~/haha# for files in haha* ; do new="prefix_$files" ; echo "$files $new" ; done
haha1 prefix_haha1
haha2 prefix_haha2
haha3 prefix_haha3
haha4 prefix_haha4
haha5 prefix_haha5
haha6 prefix_haha6
haha7 prefix_haha7

Link to this post 24 Aug 09

thanks for ur reply, :laugh: i now find another two solutions as follows,


ls  | xargs -I{} mv {} pre_{}


rename '' pre- *

Link to this post 25 Aug 09

i would like to help you but not here this is my mail

Link to this post 26 Aug 09

rename file pre-file *

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Linux Training / Board

/** BC-056 Ameex changes to add tracking code - 2016-01-22 **/ ?>