I have a directory containing bunch of .txt
files , I need a command to rename these files by one command , so their name will be : file1.txt , file2.txt, file3.txt , etc .
Any Help ?
I have a directory containing bunch of .txt
files , I need a command to rename these files by one command , so their name will be : file1.txt , file2.txt, file3.txt , etc .
Any Help ?
You can use this in terminal to rename files as you wished,
It will do the job.
Explanation:
j
, initially set it to 1*.txt
to obtain alltxt
files.mv
and increase the counter by 1.You can use the rename command, which is usually included in a default installation:
Use the -n flag if you want to do a test first:
The way this works is, for each argument, it executes the perl
s///
expression, and performs the rename from the original to the replaced string. In the replacement string I usesprintf
to format the name, where I use the environment variablec
as the counter from 1.In most cases you also may need leading "0" for each number,
%05d
does the trick, where 5 is number of digits.The following command will also rename files incrementally :
Then run this script :