我使用linux,bash。
我有一个包含100文件夹的目录,每个目录都有不同的名称。
在这100个文件夹中,都有一个名为first.bars的文件(因此我有100个名为first.bars的文件)。虽然所有名称都是first.bars,但文件实际上略有不同。
我希望将所有这些文件移动到一个新文件夹中,并重命名/编号这些文件,以便知道哪个文件来自哪个文件夹。因此,必须将第一个first.bars文件重命名为001。等。
我尝试了以下几点:
ls -d * >> /home/directorywiththe100folders/list.txt
cat list.txt | while read line;
do cd $line;
mv first.bars /home/newfolder这不工作,因为我不能有100个文件,命名相同,在一个文件夹。所以我只需要知道如何重命名它们。重命名必须连接到cat list.txt,因为第一行是移动并重命名包含第一个文件的文件夹。该文件将被称为001条。
发布于 2013-03-18 11:37:29
尝试这样做:
$ rename 's/^.*?\./sprintf("%03d.", $c++)/e' *.bar如果您想了解有关此命令的更多信息,请参见我前面给出的最近的响应:How do I rename multiple files beginning with a Unix timestamp - imapsync issue
发布于 2013-03-18 13:16:47
如果rename命令不可用,
for d in /home/directorywiththe100folders/*/; do
newfile=$(printf "/home/newfolder/%d.bars" $(( c++ )) )
mv "$d/first.bars" "$newfile"
donehttps://stackoverflow.com/questions/15475790
复制相似问题