Rename all files in the folder with increasing number

I have a folder, and inside this folder I have 10-15 files with arbitrary names. File names may contain spaces. For example: wWw.page.com __ (576)_002 . In the terminal, when I press w and then tab , the file name looks like this: wWw.page.com\ \ __\ \(576\)_0.txt .

I need a script that renames all my files, such as 0.txt , 1.txt , 2.txt , etc.

My problem: wWw.page.com __ (576)_002.txt file not found .

 index=0; for i in $(ls *.txt) do cp "${i}" $index".txt" done 
+6
source share
1 answer

Instead of ls try glob :

 index=0; for name in *.txt do cp "${name}" "${index}.txt" index=$((index+1)) done 
+14
source

Source: https://habr.com/ru/post/904400/


All Articles