dslreports logo
 
    All Forums Hot Topics Gallery
spc
Search similar:


uniqs
510

antiserious
The Future ain't what it used to be
Premium Member
join:2001-12-12
Scranton, PA

1 edit

antiserious

Premium Member

command to add numbers to files

I have a folder with 105 entries in it. I need to add a 3-character number to the front of each file name, in order, formatted like this:

001-(then the existing file name)
002-
003-

... etc, without altering the rest of the file name. I don't envision needing more than 3 numerical characters, but I'd need to have the dash at the end. There's probably a command or script that can do this, but I don't know it. Hopefully, some of you do. Thanks in advance.

edit - nevermind, krename can do it.

lugnut
@communications.com

lugnut

Anon

Open a terminal window, then type

info rename

kontos
xyzzy
join:2001-10-04
West Henrietta, NY

kontos to antiserious

Member

to antiserious
(I'm using bash)
I'd do it with a for loop:

cnt=0
for oldname in $(ls -1)
 do
   newname=$(printf "%03d-%s" $cnt $oldname)
   let "cnt++"
   mv -v $oldname $newname
 done