I have files in folder named unix_aaa.txt
unix_bbb.txt
unix_ccc.txt
and so on.
How do I change all the files that start with unix
to names like
001_unix_aaa.txt
002_unix_bbb.txt
003_unix_ccc.txt
I have files in folder named unix_aaa.txt
unix_bbb.txt
unix_ccc.txt
and so on.
How do I change all the files that start with unix
to names like
001_unix_aaa.txt
002_unix_bbb.txt
003_unix_ccc.txt
Here is a batch (windows) script that will do this
setlocal enabledelayedexpansion
set n=1
for %%a in (unix_*.txt) do (
if !n! lss 10 (
ren "%%a" "00!n!_%%a"
) else (
if !n! lss 100 (
ren "%%a" "0!n!_%%a"
) else (
if !n! geq 100 (
ren "%%a" "!n!_%%a"
)
)
)
set /a n+=1
)
This is for Bourne shells.
n=1; for f in unix*
do
mv "$f" "`printf %03d $n`_$f"
n=$((n+1))
done