ANALYSIS
Linux 每日一篇 - 35 - whereis
Linux 文件位置查找神器!掌握 whereis 命令,快速定位二进制文件、源码和手册页,让文件查找更高效!
whereis 命令是什么?
whereis 命令用于在特定标准目录中查找二进制文件、源代码文件和手册页文件的位置。与 which 命令不同,whereis 搜索更广泛的目录,包括标准的系统目录。
基本用法
PRTCL // PLAINTEXT
# 查找命令的二进制文件、源码和手册页位置whereis command_name
# 只查找二进制文件whereis -b command_name
# 只查找手册页whereis -m command_name
# 只查找源代码whereis -s command_name
# 显示详细信息whereis -u command_name # 显示未找到的类型whereis -f command_name # 显示完整路径
# 限制搜索路径whereis -B /custom/path -f command_name # 只在指定路径下搜索二进制文件whereis -M /usr/share/man -f command_name # 只在指定路径下搜索手册页whereis -S /usr/src -f command_name # 只在指定路径下搜索源代码实用技巧
PRTCL // PLAINTEXT
# 查找常用系统命令的位置whereis lswhereis pswhereis topwhereis df
# 查找开发工具whereis gccwhereis makewhereis gdbwhereis python
# 查找系统服务相关文件whereis apache2whereis nginxwhereis sshwhereis cron
# 查找库文件whereis libsslwhereis libcrypto
# 查找多个命令whereis ls cp mv grep
# 搜索手册页位置whereis -m bashwhereis -m gccwhereis -m socket
# 检查是否安装了某个软件包的源代码whereis -s nginx
# 使用 whereis 查找系统文件whereis passwdwhereis hostswhereis fstab
# 列出所有类型文件的路径whereis -bm command_name
# 检查系统命令的完整性whereis -u command_name # 显示缺失的文件类型常用场景
PRTCL // PLAINTEXT
# 检查开发环境whereis gcc g++ make cmake
# 查找网络工具位置whereis curl wget ssh ping
# 系统管理工具位置whereis useradd passwd groupmod
# 查找 Python 相关文件whereis python python-config
# 定位配置文件模板whereis fstab hosts services
# 检查系统服务组件whereis systemd init upstart
# 查找压缩工具whereis tar gzip bzip2 zip
# 验证系统命令安装完整whereis -bm ls # 检查二进制文件和手册页都存在
# 查找库函数手册whereis -m printf malloc
# 查找系统头文件位置whereis -s socket # 查找 socket 相关源码与其他查找命令的对比
PRTCL // PLAINTEXT
# whereis vs which vs locate vs find:
# whereis - 搜索标准目录下的二进制文件、源码和手册页whereis ls
# which - 只在 PATH 中搜索可执行文件which ls
# locate - 在文件数据库中快速搜索文件locate /etc/passwd
# find - 在指定路径下搜索文件find /usr -name ls -type f
# type - 显示命令的类型(别名、函数、内置命令等)type ls高级用法
PRTCL // PLAINTEXT
# 自定义搜索路径whereis -B /opt/bin -M /opt/man -f myapp
# 批量查找多个程序programs=(git curl wget docker-compose node npm)for program in "${programs[@]}"; do echo "=== $program ===" whereis "$program"done
# 检查命令的完整性check_command() { local cmd=$1 echo "Checking $cmd:" whereis -b "$cmd" # 二进制文件 whereis -m "$cmd" # 手册页 whereis -s "$cmd" # 源码}
# 搜索系统中的开发工具whereis gcc g++ clang make cmake autotools
# 查找与安全相关的命令whereis iptables firewall-cmd selinux
# 检查系统性能监控工具whereis top htop iotop vmstat iostat
# 查找网络配置工具whereis ifconfig netstat ss ip route限制和注意事项
PRTCL // PLAINTEXT
# whereis 只在预定义的标准目录中搜索# 标准二进制目录: /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin# 标准手册目录: /usr/share/man, /usr/local/man# 标准源码目录: /usr/src, /usr/local/src
# 不会搜索用户自定义目录# 对于用户安装的软件,可能需要使用 find 命令
# 搜索结果受系统配置影响# 不同的 Linux 发行版可能有不同的标准目录
# whereis 不搜索当前目录# 这与 which 和 find 不同
# 搜索速度快但范围有限# 如果需要更广泛的搜索,使用 find 或 locate 命令实际应用示例
PRTCL // PLAINTEXT
# 脚本中验证系统工具validate_system_tools() { tools=(gcc make git curl wget) for tool in "${tools[@]}"; do result=$(whereis "$tool") if [[ $result == *"$tool:"* ]]; then echo "✓ $tool 已安装: $result" else echo "✗ $tool 未找到" fi done}
# 查找系统管理命令system_admin_commands=(useradd userdel groupadd groupmod passwd chage)for cmd in "${system_admin_commands[@]}"; do whereis "$cmd"done
# 检查网络配置文件network_files=(hosts networks resolv.conf)for file in "${network_files[@]}"; do whereis "$file"done
# 查找服务管理工具whereis systemctl service initd抖音文案
🎯 Linuxwhereis 命令!
✅ 基本用法:whereis ✅ 常用参数:whereis -option ✅ 实用技巧:whereis —help
每天一个 Linux 命令,30 天变身 Linux 高手!
#Linux 入门 #Shell 命令 #程序员必备 #技术分享
关于我
全平台同名”汪多多是只猫”,专注分享实用技术教程,让你的 IT 学习之路更轻松!
关注我,每天一个 Linux 命令,轻松入门 Linux 系统!
R P
Rhine Lab Pioneer Division
Auth_Verified: 2026.04.08
Auth_Verified: 2026.04.08
