常用的函数式命令

1、解压RPM包(类似 rpmdev-extract 命令)

rpm_extract() {
    rpm_file="$1"
    rpm2cpio "$rpm_file" | cpio -idmv
}

# 用法: rpm_extract nginx-1.26.3-1.el9.ngx.x86_64.rpm

2、列出软件包的所有可用版本

yum_list_duplicates() {
    package="$1"
    yum list --showduplicates "$package"
}

# 用法: yum_list_duplicates nginx

3、解压.tar.gz文件

tar_gz_extract() {
    tar_file="$1"
    tar -xzvf "$tar_file"
}

# 用法: tar_gz_extract nginx-1.26.3.tar.gz

4、压缩目录为.tar.gz文件

tar_gz_compress() {
    dir_to_compress="$1"
    output_file="$2"
    tar -czvf "$output_file" "$dir_to_compress"
}

# 用法: tar_gz_compress nginx-1.26.3 nginx-1.26.3.tar.gz

5、查找指定目录下的特定类型文件

find_files_by_type() {
    search_dir="$1"
    file_type="$2"
    find "$search_dir" -type f -name "*.$file_type"
}

# 用法: find_files_by_type /usr/local/bin py

6、检查网站是否可达

check_website() {
    website_url="$1"
    if curl --output /dev/null --silent --head --fail "$website_url"; then
        echo "$website_url 可达"
    else
        echo "$website_url 不可达"
    fi
}

# 用法: check_website https://www.google.com
posted @ 2025-04-18 18:25  wanghongwei-dev  阅读(7)  评论(0)    收藏  举报