写一个shell,把一个目录下所有的子目录中的文件移至本目录中,并且在文件名的前面加上子目录的文件夹名
5 个解决方案
#1
顶一下 有人会么
#2
#!/bin/bash
father_path="/path/"
son_path=`ls ${father_path}`
for sonpath in ${son_path}
do
file_name=`ls ${father_path}${sonpath}`
for filename in ${file_name}
do
mv "${father_path}${sonpath}/${filename}" "./${sonpath}${filename}"
done
done
#3
这个 son_path 有可能不是文件夹啊
#4
那你自己加个判断就可以了哇!
#!/bin/bash
father_path="/path/"
son_path=`ls ${father_path}`
for sonpath in ${son_path}
do
if test -d "${father_path}${sonpath}"
then
file_name=`ls ${father_path}${sonpath}`
for filename in ${file_name}
do
mv "${father_path}${sonpath}/${filename}" "./${sonpath}${filename}"
done
fi
done
#5
谢谢了
#1
顶一下 有人会么
#2
#!/bin/bash
father_path="/path/"
son_path=`ls ${father_path}`
for sonpath in ${son_path}
do
file_name=`ls ${father_path}${sonpath}`
for filename in ${file_name}
do
mv "${father_path}${sonpath}/${filename}" "./${sonpath}${filename}"
done
done
#3
这个 son_path 有可能不是文件夹啊
#4
那你自己加个判断就可以了哇!
#!/bin/bash
father_path="/path/"
son_path=`ls ${father_path}`
for sonpath in ${son_path}
do
if test -d "${father_path}${sonpath}"
then
file_name=`ls ${father_path}${sonpath}`
for filename in ${file_name}
do
mv "${father_path}${sonpath}/${filename}" "./${sonpath}${filename}"
done
fi
done
#5
谢谢了