Having done something like this before, I can assure you it's easy to make a typo that will give you an even larger problem that you already have. Use this information at your own risk.
At bash prompt;
i=0 ; for f in `ls -rt` ; do i=$(expr $i + 1); mv $f $i.txt; done
i
acts as a counterls -rt
lists files in reverse order by modification time - if you've copied, moved or otherwise modified the files, this may not give you the file ordering you expect. Check it carefully by runningls -rt
as a separate command and check it - twice.for f in
ls -rt; do
iterates of the list of files with 'f' taking on each file namei=$(expr $i + 1)
increments the countermv $f $i.txt
renames the file using the counter, and adding the .txt extensiondone
closes the loop- note that commands in the loop are separated by semicolons, so if you add another command, follow it with a semicolon