bash: /usr/bin/sed: 没有这样的文件或目录

bash: /usr/bin/sed: 没有这样的文件或目录

在测试服务器上,我故意删除了?????-/我期望删除符号链接/lib64和目录。/media一切都很顺利(一切都坏了),但后来我对下面的输出感到好奇:

[root@testserver /]# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  rh_share3  root  run  sbin  srv  sys  tmp  usr  var
[root@testserver /]# rm -rf ?????
bash: /usr/bin/sed: No such file or directory
[root@testserver /]# ls
bash: /usr/bin/ls: No such file or directory
bash: /usr/bin/sed: No such file or directory

我看到某些软件包具有sed依赖性,但我不明白为什么它需要sed像按这样简单的东西Enter

[root@testserver bin]# rpm -q --whatrequires sed
krb5-libs-1.17-18.el8.x86_64
ca-certificates-2019.2.32-80.0.el8_1.noarch
dracut-049-70.git20200228.el8.x86_64
crypto-policies-20191128-2.git23e1bf1.el8.noarch
policycoreutils-2.9-9.el8.x86_64
authselect-libs-1.1-2.el8.x86_64
cups-filters-1.20.0-19.el8.x86_64
open-vm-tools-11.0.0-4.el8.x86_64
authselect-compat-1.1-2.el8.x86_64
dhcp-client-4.3.6-40.el8.x86_64
nfs-utils-2.3.3-31.el8.x86_64
autofs-5.1.4-40.el8.x86_64

为什么会bash: /usr/bin/sed: No such file or directory出现这条线?显然sed被认为是缺失的,但为什么它会被调用呢?如果我只是运行一个strace -o bash bash.我知道sed代表stream editor- 是否每个 bash 命令都运行过sed,或者还会发生什么?

操作系统是带有 GUI 的 OOTB RHEL 8.2 (Oopta)。

编辑

以下是输出set | grep sed

[user1@testserver ~]$ set | grep sed
    local command=$(HISTTIMEFORMAT= history 1 | sed 's/^ *[0-9]\+ *//');
                COMPREPLY=($( compgen -W "$( bpftool help 2>&1 |                     command sed                     -e '/OBJECT := /!d'                     -e 's/.*{//'                     -e 's/}.*//'                     -e 's/|//g' )" -- "$cur" ));
    COMPREPLY+=($( compgen -W "$( bpftool -jp btf 2>&1 |         command sed -n 's/.*"id": \(.*\),$/\1/p' )" -- "$cur" ))
    COMPREPLY+=($( compgen -W "$( bpftool -jp map  2>&1 |         command sed -n 's/.*"id": \(.*\),$/\1/p' )" -- "$cur" ))
    COMPREPLY+=($( compgen -W "$( bpftool -jp map  2>&1 |         command grep -C2 "$type" |         command sed -n 's/.*"id": \(.*\),$/\1/p' )" -- "$cur" ))
    COMPREPLY+=($( compgen -W "$( bpftool -jp prog 2>&1 |         command sed -n 's/.*"id": \(.*\),$/\1/p' )" -- "$cur" ))
    COMPREPLY+=($( compgen -W "$( bpftool -jp prog 2>&1 |         command sed -n 's/.*"tag": "\(.*\)",$/\1/p' )" -- "$cur" ))
    type=$(bpftool -jp map show $keyword $ref |         command sed -n 's/.*"type": "\(.*\)",$/\1/p');
        COMPREPLY=($( compgen -W "$( command sed -ne 's|^iface \([^ ]\{1,\}\).*$|\1|p'            /etc/network/interfaces /etc/network/interfaces.d/* 2>/dev/null )"             -- "$cur" ));
            COMPREPLY=($( compgen -W "$( printf '%s\n'             /etc/sysconfig/network/ifcfg-* |             command sed -ne 's|.*ifcfg-\([^*].*\)$|\1|p' )" -- "$cur" ));
                COMPREPLY=($( compgen -W "$( command ls -B             /etc/sysconfig/interfaces |             command sed -ne 's|.*ifcfg-\([^*].*\)$|\1|p' )" -- "$cur" ));
                COMPREPLY=($( compgen -W "$( printf '%s\n'             /etc/sysconfig/network-scripts/ifcfg-* |             command sed -ne 's|.*ifcfg-\([^*].*\)$|\1|p' )" -- "$cur" ));
    local included=$( command sed -ne 's/^[[:blank:]]*[Ii][Nn][Cc][Ll][Uu][Dd][Ee][[:blank:]]\{1,\}\([^#%]*\)\(#.*\)\{0,1\}$/\1/p' "${configfile}" );
    COMPREPLY+=($( compgen -W         "$( { LC_ALL=C ifconfig -a || ip addr show; } 2>/dev/null | command sed -ne             's/.*addr:\([^[:space:]]*\).*/\1/p' -ne             's|.*inet[[:space:]]\{1,\}\([^[:space:]/]*\).*|\1|p' )"         -- "$cur" ))
    [[ $# -ge $OPTIND ]] && echo "error: $FUNCNAME("$@"): unprocessed arguments:" $(while [[ $# -ge $OPTIND ]]; do printf '%s\n' ${!OPTIND}; shift; done);
        local hosts=$( command sed -ne 's/^[[:blank:]]*[Hh][Oo][Ss][Tt][[:blank:]]\{1,\}\([^#*?%]*\)\(#.*\)\{0,1\}$/\1/p' "${config[@]}" );
            local argtype=$( LC_ALL=C $1 --help 2>&1 | command sed -ne                 "s|.*$prev\[\{0,1\}=[<[]\{0,1\}\([-A-Za-z0-9_]\{1,\}\).*|\1|p" );
        COMPREPLY=($( compgen -W "$( LC_ALL=C $1 --help 2>&1 |             command sed -ne 's/.*\(--[-A-Za-z0-9]\{1,\}=\{0,1\}\).*/\1/p' | sort -u )"             -- "$cur" ));
    COMPREPLY+=($(         { LC_ALL=C ifconfig -a || ip link show; } 2>/dev/null | command sed -ne         "s/.*[[:space:]]HWaddr[[:space:]]\{1,\}\($re\)[[:space:]].*/\1/p" -ne         "s/.*[[:space:]]HWaddr[[:space:]]\{1,\}\($re\)[[:space:]]*$/\1/p" -ne         "s|.*[[:space:]]\(link/\)\{0,1\}ether[[:space:]]\{1,\}\($re\)[[:space:]].*|\2|p" -ne         "s|.*[[:space:]]\(link/\)\{0,1\}ether[[:space:]]\{1,\}\($re\)[[:space:]]*$|\2|p"
    COMPREPLY+=($( { arp -an || ip neigh show; } 2>/dev/null | command sed -ne         "s/.*[[:space:]]\($re\)[[:space:]].*/\1/p" -ne         "s/.*[[:space:]]\($re\)[[:space:]]*$/\1/p" ));
    COMPREPLY+=($( command sed -ne         "s/^[[:space:]]*\($re\)[[:space:]].*/\1/p" /etc/ethers 2>/dev/null ));
    COMPREPLY=($( compgen -W "$( command ls -RL $modpath 2>/dev/null |         command sed -ne 's/^\(.*\)\.k\{0,1\}o\(\.[gx]z\)\{0,1\}$/\1/p' )" -- "$cur" ))
        COMPREPLY=($( compgen -X '<defunct>'             -W '$( command ps axo comm | command sed -e 1d )' -- "$cur" ));
        COMPREPLY=($( compgen -X '<defunct>' -W '$( command ps axo command= | command sed -e \
        COMPREPLY=($( compgen -W '`command sed -e "y/|/ /" \
    COMPREPLY+=($( compgen -W         "$( command sed -ne 's/^\([^[:space:]#|]\{2,\}\)|.*/\1/p' /etc/termcap             2>/dev/null )" -- "$cur" ));

答案1

导致此行为的文件vte.sh位于/etc/profile.d/

VTE 配置的一方面是使用/etc/profile.d/vte.sh. VTE 使用此脚本来覆盖,PROMPT_COMMAND以便通过终端控制代码向自身提供附加信息。特别地,该脚本用于告诉VTE shell的当前目录。以前,VTE 组件用于读取此内容, /proc/<pid>/cwd但根据 VTE 上游,这种方法存在许多问题,因此更改为 /etc/profile.d/vte.sh.

来源

仅当使用 GNOME 终端时,通过 SSH 不会出现此行为。如果对 Windows 系统有更好了解的人愿意写一个更详细的答案,我很乐意接受,因为目前我对 GNOME 的理解有限。

答案2

思考问题是你已经重写了command, 一个内置函数:

$ help command | head --lines=2
command: command [-pVv] command [arg ...]
    Execute a simple command or display information about commands.

command通常用于忽略别名和函数以直接显式运行内置或可执行文件。这对于避免无限循环很有用。例如:

ls() {
    command ls --color=auto
}

这会调用ls可执行文件,而不是永远递归地调用自身。

unset commandcommand并在您的 Bash 配置文件中查找 的任何用途。

答案3

这只是推测,但sed可能是动态链接的 64 位二进制文​​件。通过删除lib64,内核将无法再找到执行所需的动态链接器sed(可能还有其他所有内容)。不是no such file or directory用于sed,而是用于链接器。

答案4

这是由于 /etc/profile.d/vte.sh

case "$TERM" in
  xterm*|vte*)
    [ -n "$BASH_VERSION" ] && PROMPT_COMMAND="__vte_prompt_command"
    [ -n "$ZSH_VERSION"  ] && precmd_functions+=(__vte_osc7)
    ;;
esac
vte_prompt_command() {
  ######### HERE : bash tries to look up comletions with sed ###
  local command=$(HISTTIMEFORMAT= history 1 | sed 's/^ *[0-9]\+ *//')
  ############################################################
  command="${command//;/ }"
  local pwd='~'
  [ "$PWD" != "$HOME" ] && pwd=${PWD/#$HOME\//\~\/}
  printf "\033]777;notify;Command completed;%s\007\033]0;%s@%s:%s\007%s" "${command}" "${USER}" "${HOSTNAME%%.*}" "${pwd}" "$(__vte_osc7)"
}

只需删除它(然后你必须使用正确的文件名)

sed 's/^ *[0-9]\+ *//'

固定的!

相关内容