使用rar提取分割存档文件的Bash脚本
以下是我想做的: 我有上千个文件夹名档案的分割rar档案。 文件0001.part1.rar 0002.part2.rar 0003.part3.rar等的名称使用rar提取分割存档文件的Bash脚本,bash,unix,split,rar,Bash,Unix,Split,Rar,以下是我想做的: 我有上千个文件夹名档案的分割rar档案。 文件0001.part1.rar 0002.part2.rar 0003.part3.rar等的名称 阅读0001.part1.rar 根据上面文件的前缀创建目录,例如0001 在上面创建的目录中移动具有相同前缀的所有文件 提取该目录中的文件 删除该目录中的所有rar文件 根据文本文件中的名称列表重命名提取的文件 使用不同的参数对重命名的文件进行Rar 将重命名的文件(从步骤6)移动到名为Done的新目录 转至文件0002.part1.
file.001
file.002
file.003
等等,我也需要提取
步骤6的澄清:
Go back to the main folder with all the other archives
and continue extracting the next set of archives and
do the same steps from 1 to 8.
提取第二组rar后(file.001、file.002等)
我想根据文本文件中的名称列表对其进行重命名
e、 g.文本文件中的文件列表:
0001 - GB Funds.DAT
0002 - US Bonds.DAT
0003 - SG Securities.DAT
0004 - LU Credits.DAT
第7步的澄清:
After renaming the file I want to move it on a new folder called "Done"
步骤9的澄清:
Go back to the main folder with all the other archives
and continue extracting the next set of archives and
do the same steps from 1 to 8.
您可以编写包含以下内容的shell脚本:
# foo.sh
set -e
set -u
for i in `find -max-depth 1 -type f -name '*.rar' | sed 's/\.part*\.rar$//' | sort -u`; do
mkdir $i
mv $i.part*rar $i
cd $i
unrar x $i.part1.rar
DST=`grep $i ../rename.txt | sed 's/^[0-9]\+ - //'`
mv $i "$DST"
# and so on, rar it together again, move it done directory etc.
cd ..
done
然后通过以下方式运行:
bash foo.sh
你必须澄清6/8/9
我不知道为什么要通过cron运行它,因为您只想运行一次。at设计用于运行一次性作业,或在屏幕会话中运行
在开始整个工作之前,我建议您使用收藏中的1-3个文件和最终使用的脚本进行一些测试。您需要
cd
返回父目录或使用pushd
/popd
(或子shell)。您好,maxschlepzig我回答了您的问题。网站不允许长时间的回复,所以我更新了上面的主要问题。@Dennis Williamson:因为脚本只是一个脚手架,cd。。还有其他的东西被遗漏了@法内维尔:我更新了我的答案,以显示如何重命名提取的文件。