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
.
我有一个文件夹,在该文件夹中我有10-15个任意名称的文件。文件名可以包含空格。例如:wWw.page.com __(576)_002。在终端中,当我按w然后选项卡时,文件名显示如下: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.
我想要一些脚本,将重命名我的所有文件,如0.txt,1.txt,2.txt等。
My problem is: wWw.page.com __ (576)_002.txt file not found
.
我的问题是:找不到wWw.page.com __(576)_002.txt文件。
index=0;
for i in $(ls *.txt)
do
cp "${i}" $index".txt"
done
1 个解决方案
#1
14
Instead of ls
try to glob
:
而不是ls尝试glob:
index=0;
for name in *.txt
do
cp "${name}" "${index}.txt"
index=$((index+1))
done
#1
14
Instead of ls
try to glob
:
而不是ls尝试glob:
index=0;
for name in *.txt
do
cp "${name}" "${index}.txt"
index=$((index+1))
done