求分批打包文件夹的Shell脚本
某个文件夹有200个mp3,要求每20个打包成一个包,一共是10个能够独立解压的压缩包。最好打包好的文件包括原来的文件夹。 [i=s] 本帖最后由 netdzb 于 2019-6-20 18:12 编辑 [/i]
[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=221204&ptid=53111]1#[/url] [i]netdzb[/i] [/b]
我自己写的脚本,看看有问题吗?
200首歌曲,打包成20个压缩包,
可以单独解压。
#!/bin/bash
for FILE in (*.mp3)
do
count = 0
while [ $count -lt 10 ]
do
songs = 0
rar a -ep $songs $FILE
count = $((count + 1))
songs = $((songs + 1))
done
done [b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=221204&ptid=53111]1#[/url] [i]netdzb[/i] [/b]
又改了一下,看看有问题吗?
#!/bin/bash
for FILE in (*.mp3)
songs = 0
do
count = 0
while [ $count -lt 10 ]
do
rar a -ep $songs $FILE
count = $((count + 1))
done
songs = $((songs + 1))
done [b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=221211&ptid=53111]3#[/url] [i]netdzb[/i] [/b]
#!/bin/bash
let songs=0
for FILE in *.mp3
do
let count=0
while ((count<30));
do
rar a -ep $songs.rar $FILE
let count+=1
done
let songs+=1
done
代码没问题了,运行结果不对。看来还得改啊。 [b]回复 [url=http://bbs.bathome.net/redirect.php?goto=findpost&pid=221216&ptid=53111]4#[/url] [i]netdzb[/i] [/b]
不要用 while 做判断,用 if 判断试试。 [b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=221217&ptid=53111]5#[/url] [i]Batcher[/i] [/b]
#!/bin/bash
let songs=0
for FILE in *.mp3
do
let count=0
while ((count<30));
do
rar a -ep $songs.rar $FILE
~~~~~~~~~~~~~~~~~
这里改成 rar a -ep songs.rar $FILE
部分就对了,那样只会压缩成一个包。如果按照上面写会被压缩成200个压缩包,和我的要求不符合
哪里有不对啊。
let count+=1
done
let songs+=1
done [b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=221217&ptid=53111]5#[/url] [i]Batcher[/i] [/b]
搞定了,不过还是有问题。打包的速度太慢了,和gui添加文件压缩的速度没法比,太慢了。405个文件,用这个脚本用了一个小时。双核笔记本,移动
sata硬盘。
#!/bin/bash
let songs=0
let count=0
for FILE in *.mp3
do
if ((count<30)); then
rar a -ep $songs $FILE
let count+=1
else
let count=0
let songs+=1
fi
done [b]回复 [url=http://bbs.bathome.net/redirect.php?goto=findpost&pid=221222&ptid=53111]7#[/url] [i]netdzb[/i] [/b]
优化的思路是减少 rar 命令执行的次数[code]#!/bin/bash
let songs=0
let count=0
FileList=""
for FILE in *.mp3; do
let count+=1
FileList="$FileList $FILE"
if [[ $count == 30 ]]; then
rar a -ep $songs.rar $FileList
FileList=""
let songs+=1
let count=0
fi
done
rar a -ep $songs.rar $FileList[/code] [b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=221230&ptid=53111]8#[/url] [i]Batcher[/i] [/b]
这个脚本改成7z可以吗? 7z有没有文件列表呢? [b]回复 [url=http://bbs.bathome.net/redirect.php?goto=findpost&pid=221233&ptid=53111]9#[/url] [i]netdzb[/i] [/b]
可以。有的。 [b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=221230&ptid=53111]8#[/url] [i]Batcher[/i] [/b]
谢谢,这个脚本执行速度很快,10分钟内搞定了。
页:
[1]