可以使用bash for loop和
mv:
for subdir in *; do mv $subdir/file.txt $subdir.txt; done;
请注意,如果目录名称包含空格,则上述解决方案将不起作用。相关链接。
另一种基于注释的解决方案(也适用于名称中也包含空格的目录):
find . -type d -not -empty -exec echo mv {}/file.txt {}.txt ;
可以使用bash for loop和
mv:
for subdir in *; do mv $subdir/file.txt $subdir.txt; done;
请注意,如果目录名称包含空格,则上述解决方案将不起作用。相关链接。
另一种基于注释的解决方案(也适用于名称中也包含空格的目录):
find . -type d -not -empty -exec echo mv {}/file.txt {}.txt ;