复制成功
请遵守本站许可
REPORT
Chapter_Post // Field_Report

Post_Ref: RL-LINUX每日命

2026.04.08

Linux每日命令-35-whereis

Echo HaoRan
Echo HaoRan
#计划任务
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 ls
whereis ps
whereis top
whereis df
# 查找开发工具
whereis gcc
whereis make
whereis gdb
whereis python
# 查找系统服务相关文件
whereis apache2
whereis nginx
whereis ssh
whereis cron
# 查找库文件
whereis libssl
whereis libcrypto
# 查找多个命令
whereis ls cp mv grep
# 搜索手册页位置
whereis -m bash
whereis -m gcc
whereis -m socket
# 检查是否安装了某个软件包的源代码
whereis -s nginx
# 使用 whereis 查找系统文件
whereis passwd
whereis hosts
whereis 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
// END OF POST

订阅

通过 RSS 订阅本站,新文章发布时第一时间收到通知。

Follow
Classified
Chapter_06
Protocol_Ref: CC-BY-NC-SA-4.0

Linux每日命令-35-whereis

Author: CHONGXIReleased: 2026.04.08

Licensed under CC BY-NC-SA 4.0

评论

© 2025-2026 EchoSpace
Powered by Astro & echohaoran Non-Collaborative_Entity // Protocol_V.4.21