关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

centos批量RAR压缩的脚本实现

发布时间:2024/7/2 15:06:27
香港云服务器

#!/bin/bash

# 指定需要压缩的文件夹

source_dir="/path/to/source_dir/"

# 指定压缩后的文件夹

target_dir="/path/to/target_dir/"

# 指定压缩后的文件名

output_file="output.rar"

# 切换到源文件夹目录

cd $source_dir

# 遍历源文件夹下的所有文件

for file in $(ls $source_dir)

do

    # 判断是否为文件

    if [ -f $file ]; then

        # 进行RAR压缩

        rar a $target_dir$output_file $file

    fi

done

echo "RAR压缩完成"

将以上代码保存为一个.sh文件,然后给予执行权限:

chmod +x batch_rar.sh

接着执行该脚本文件即可实现批量RAR压缩。注意替换脚本中的source_dirtarget_diroutput_file变量为实际路径和文件名。