简体   繁体   中英

Rename all the files in the folder with increasing numbers

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

I want some script that will rename all my files like this 0.txt , 1.txt , 2.txt and so on.

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

index=0;
for i in $(ls *.txt)
do
    cp "${i}"  $index".txt" 
done

Instead of ls try to glob :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM