在 Linux 系统中,常用的命令主要存放在以下几个标准目录中,这些目录通常已包含在系统的 PATH 环境变量中(可通过 echo $PATH 查看):
/binls, cp, mv, rm, cat, echo, bash 等。/usr/bingcc, python, ssh, git, man 等。apt、yum)安装的软件会放在这里。/sbinroot)执行的命令,如:
fdisk, ifconfig, iptables, reboot, shutdown 等。/usr/sbin/sbin,但通常是非核心的管理工具,如:
useradd, sshd, cron 等。/usr/local/binpython3.10、自定义脚本等。~/.local/binPATH),常见于:
pip install --user 安装的 Python 工具(如 pipx)。/usr/share:存放命令的文档、帮助文件(如 man 手册)。/etc:存放命令的配置文件(如 /etc/ssh/sshd_config)。which 命令:
bash
which ls # 输出示例: /bin/ls
which python # 输出示例: /usr/bin/pythonwhereis 命令(同时显示二进制、源码和手册位置):
bash
whereis grep # 输出示例: grep: /bin/grep /usr/share/man/man1/grep.1.gztype 命令(区分内置命令和外部命令):
bash
type cd # 输出示例: cd is a shell builtin
type ping # 输出示例: ping is /bin/pingPATH 中,需通过绝对路径执行(如 /opt/myapp/bin/start.sh)。