shell 判断可执行文件

写一个脚本,找出rpm包里的所有的命令文件

你可以使用下面的 bash 脚本来获取 RPM 包中所有命令文件的列表:

#!/bin/bash

if [ $# -ne 1 ]; then
  echo "Usage: $0 <RPM package>"
  exit 1
fi

RPM_PACKAGE=$1

if [ ! -f $RPM_PACKAGE ]; then
  echo "Error: $RPM_PACKAGE does not exist."
  exit 1
fi

# Extract the contents of the RPM package to a temporary directory
TEMP_DIR=`mktemp -d`
rpm2cpio $RPM_PACKAGE | cpio -idmv $TEMP_DIR

# Search for all executable files in the temporary directory
find $TEMP_DIR -type f -executable | while read file; do
  # Skip files that are not in the standard PATH
  if [[ "$file" != "/usr/bin/"* ]] && [[ "$file" != "/usr/sbin/"* ]]; then
    continue
  fi
  echo $file
done

# Clean up the temporary directory
rm -rf $TEMP_DIR

脚本将输出 RPM 包中所有命令文件的列表,这些文件通常位于 /usr/bin/usr/sbin 目录下。

如果有的命令文件不在/usr/bin 或 /usr/sbin目录下,怎么办

如果 RPM 包中的命令文件不在 /usr/bin/usr/sbin 目录下,可以通过修改脚本来处理。

例如,如果命令文件存在于 /usr/local/bin 目录下,则可以更改脚本中的判断:

# Search for all executable files in the temporary directory
find $TEMP_DIR -type f -executable | while read file; do
  # Skip files that are not in the standard PATH
  if [[ "$file" != "/usr/bin/"* ]] && [[ "$file" != "/usr/sbin/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值