In your specific case, you want to use mmv as follows:
pax> ll total 0 drwxr-xr-x+ 2 allachan None 0 Dec 24 09:47 . drwxrwxrwx+ 5 allachan None 0 Dec 24 09:39 .. -rw-r--r-- 1 allachan None 0 Dec 24 09:39 file1.txt -rw-r--r-- 1 allachan None 0 Dec 24 09:39 file2.avi pax> mmv '*.*' '#1_#1.#2' pax> ll total 0 drwxr-xr-x+ 2 allachan None 0 Dec 24 09:47 . drwxrwxrwx+ 5 allachan None 0 Dec 24 09:39 .. -rw-r--r-- 1 allachan None 0 Dec 24 09:39 file1_file1.txt -rw-r--r-- 1 allachan None 0 Dec 24 09:39 file2_file2.avi
You need to know that wildcards are not greedy. This means that the abtxt file will be converted to a_a.b.txt , not a.b_a.b.txt .
mmv was installed as part of my cygwin, but I had to
sudo apt-get install mmv
in my ubuntu field to get it. If this is not a standard distribution, any package manager that you use, we hope that it will be available.
If for some reason you are not allowed to install it, you will have to use one of the other bash for -loop solutions shown in the other answers. I prefer twisting mmv own, but you may not be able to.
source share