2013-01-11 50 views
0

我有一个程序将文件提取到一系列子文件夹,每个子文件夹都带有一个“标题”子文件夹。例如:将指定文件夹中的所有文件上移到一个目录中

/share/Videos/Godfather.Part.1 
    /share/Videos/Godfather.Part.1/<packagename> 
    /share/Videos/Godfather.Part.1/<packagename>/Godfather.avi 
/share/Videos/Godfather.Part.2 
    /share/Videos/Godfather.Part.2/<packagename> 
    /share/Videos/Godfather.Part.2/<packagename>/Godfather2.avi 

我想取文件中指定的文件夹<packagename>然后向上移动一个目录下,这样的文件结构如下所示:

/share/Videos/Godfather.Part.1 
    /share/Videos/Godfather.Part.1/Godfather.avi 
/share/Videos/Godfather.Part.2 
    /share/Videos/Godfather.Part.2/Godfather2.avi 

我怎样才能做到这一点任务在bash命令行?请注意,这是一个使用2个文件夹的例子,我有100个这样的文件夹。

回答

2

分享和享受。

for i in `find . -name "*avi"` 
do 
    dest=`dirname $i` 
    mv $i $dest/.. 
done 
+0

感谢您的回答。这有帮助,但我只想要名为的特定子文件夹中的文件。 –

+1

使用'-path“* /*。avi”'而不是'-name“* .ave”'。 – Barmar

+0

很好,谢谢! –

相关问题