【发布时间】:2011-09-11 08:52:48
【问题描述】:
我的目录有 2 个子目录,并且子目录也很少,而且它们有一些文件。我需要重命名所有文件以将 html 扩展名附加到文件名。 目录结构是这样的
main-directory
sub-directory
sub-directory
sub-directory
file1
file2
and so on to lot of files
现在我不能使用这样的东西
for file in main-directory/*
do
if [ -f "$file" ]
then `mv "$file" "$file.html"`
fi
done
因为 for 循环不会递归地使用路径。所以我用了这样的东西
for file in `ls -1R main-directory` // -1 for showing file and directory names separated by new lines and -R for recursive travel
do
if [ -f "$file" ]
then `mv "$file" "$file.html"`
fi
done
以上代码无法重命名文件。检查是否行
for file in `ls -1R main-directory`
正在工作,我写了这样的东西
for file in `ls -1R main-directory`
do
if [ -f "$file" ]
echo $file
done
这不显示任何内容。有什么问题?
【问题讨论】:
标签: linux bash for-loop directory file-rename