Bash 脚本使用 rar 提取分割存档文件

发布于 2024-09-16 14:14:49 字数 1120 浏览 3 评论 0原文

这就是我想要做的:

我在文件夹名称 Archives 上有数千个分割的 rar 存档。 文件名 0001.part1.rar 0002.part2.rar 0003.part3.rar 等等

  1. 读取 0001.part1.rar
  2. 根据上面文件的前缀创建一个目录,例如 0001
  3. 将所有具有相同前缀的文件移动到创建的目录上多于。
  4. 提取该目录中的文件
  5. 删除该目录中的所有 rar 文件
  6. 根据文本文件中的名称列表重命名提取的文件。
  7. Rar 具有不同参数的重命名文件。
  8. 将重命名的文件(来自步骤 6)移动到名为 Done 的新目录。
  9. 继续处理文件 0002.part1.rar,然后执行步骤 2-8 等等。

另外我如何将它与 cron 合并??? 这应该只运行一次...

在提取第一组 rar 文件后,更改为:

file.001 
file.002 
file.003 

等我也需要提取。

对第 6 步的说明

提取第二组 rar 后(file.001、file.002 等) 我想根据文本文件中的名称列表重命名它。

例如,文本文件中的文件列表:

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.

Here's what I want to do:

I have thousand of split rar archives on folder name Archives.
Name of the files 0001.part1.rar 0002.part2.rar 0003.part3.rar etc.

  1. read 0001.part1.rar
  2. create a directory based on prefix of the file above e.g. 0001
  3. move all files with the same prefix on the directory created above.
  4. Extract the files within that directory
  5. delete all rar files in that directory
  6. Rename the extracted file based on a list of names from a text file.
  7. Rar the renamed file with different arguments.
  8. Move the renamed file (from step 6) to a new directory called Done.
  9. Proceed to file 0002.part1.rar then do steps 2-8 and so forth.

Additional how would I incorporate it with cron???
This should be run once only...

After extracting the first set of rar's files change to:

file.001 
file.002 
file.003 

etc. which I need to extract too.

Clarification on Step 6:

After extracting the second set of rar's (file.001 , file.002 etc.)
I want to rename it based on a list of names from a text file.

e.g. List of files from a text file:

0001 - GB Funds.DAT
0002 - US Bonds.DAT
0003 - SG Securities.DAT
0004 - LU Credits.DAT

Clarification on Step 7:

After renaming the file I want to move it on a new folder called "Done"

Clarification on Step 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奢华的一滴泪 2024-09-23 14:14:49

您可以编写一个 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 个文件以及最终得到的脚本进行一些测试。

You can write a shell script including something like this:

# 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

Run it then via:

bash foo.sh

You have to clarify 6./8./9.

I don't know why do you want to run it via cron, since you only want to run it once. at is designed for running one-time jobs, or run it in a screen session.

I suggest that you do a few tests with 1-3 files from your collection and the script you end up with, before starting the whole job.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文