N
N
Nikita2022-03-12 20:22:53
linux
Nikita, 2022-03-12 20:22:53

How can I write a bash command to rename all files in a directory to 0.bmp 1.bmp 2.bmp...?

There is a directory containing a large number of files (on the order of several hundred thousand) of the bmp extension . It is necessary to rename all these files as follows:
0.bmp
1.bmp
2.bmp
3.bmp
4.bmp
5.bmp
6.bmp
7.bmp
8.bmp
...


It is clear that you can write some kind of tin in 100 lines in python, but I would like an elegant solution in the form of a single bash command. Drop it if anyone has it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xotkot, 2022-03-12
@gth-other

eval $(ls |awk '{i++;print "mv "$0" "i".bmp;"}')
for safety, if there are spaces in the names, then you first need to put them in quotes ' (\x27)

eval $(ls |awk '{i++;print "mv \x27"$0"\x27 "i".bmp;"}')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question