查找Linux系统中某个软件是否安装/存在
- 通用方法--不区分Linux版本
- locate查找--`推荐`
- 从进程查看
- 用which查看
- whereis查找
- command命令
- type定位命令行
- 从用户自定义的变量中查询
- find--终极办法
- Cetnos系统
- 用yum查看--仅适用于yum安装
- 用rpm查看
- Ubuntu系统
- 用dpkg查看
- find加强
通用方法–不区分Linux版本
参考 https://blog.csdn/weixin_39611754/article/details/113328255
locate查找–推荐
locate基于find.
优点
是查找速度非常快
,秒查。
缺点
是依赖索引数据库
,非实时查找,数据库每天更新一遍.所以可能找不到最新的文件。
# 安装mlocate
yum install mlocate -y
# 手动更新索引数据库
updatedb
# 查找nginx
locate nginx
从进程查看
# 过滤nginx进程
ps aux | grep nginx
## 打印结果
[root@liqiaofei-test ~]# ps aux|grep nginx
root 414 0.0 0.0 39304 960 ? Ss 09:51 0:00 nginx: master process /usr/sbin/nginx
nginx 415 0.0 0.1 39724 2328 ? S 09:51 0:00 nginx: worker process
nginx 8833 0.0 0.2 232664 4080 ? S 09:58 0:00 php-fpm: pool www
nginx 8834 0.0 0.2 232664 4664 ? S 09:58 0:00 php-fpm: pool www
nginx 8835 0.0 0.3 232664 5480 ? S 09:58 0:00 php-fpm: pool www
nginx 8836 0.0 0.2 232664 4080 ? S 09:58 0:00 php-fpm: pool www
nginx 8837 0.0 0.2 232664 4664 ? S 09:58 0:00 php-fpm: pool www
root 18586 0.0 0.0 112812 976 pts/3 R+ 10:31 0:00 grep --color=auto nginx
用which查看
which命令的作用是在PATH变量指定的路径中,搜索某个系统命令的位置,并且返回第一个搜索结果。
原理同下.
[root@liqiaofei-test ~]# which nginx
/usr/sbin/nginx
whereis查找
Whereis和which功能类似,但是它不仅能找到程序路径,还会列出程序的man手册
https://linux/article-15446-1.html
# 查找nginx
whereis nginx
command命令
command -v
命令会先检查指定命令是否为内置命令
或者别名
,如果是,则输出对应的信息。否则,会在环境变量$PATH
指定的路径中查找指定命令的可执行文件,并输出第一个匹配到的可执行文件路径
。
# 查看ls的位置
command -v ls
# 查看cat的位置
command -v cat
type定位命令行
# 定位dig命令
type -a dig
从用户自定义的变量中查询
用户用源码或二进制包安装的程序,为了便于操作,一般都会设置变量
# 查看/etc/prifle
cat /etc/profile |grep nginx
# 查看~/.bashrc
cat ~/.bashrc |grep nginx
# 查看~./bash_profile
cat ~/.bash_profile |grep nginx
find–终极办法
效率最低的方式,不推荐
# 查找nginx文件
find / --name nginx
Cetnos系统
用yum查看–仅适用于yum安装
# 从yum已安装列表中过滤
yum list installed|grep nginx
## 打印结果
[root@liqiaofei-test ~]# yum list installed|grep nginx
nginx.x86_64 1:1.20.1-2.el7 @epel
nginx-filesystem.noarch 1:1.20.1-2.el7 @epel
用rpm查看
# rpm-qa模糊查询
##rpm -qa | grep “软件或者包的名字”。
rpm -qa|grep ngin
## 打印结果
[root@liqiaofei-test ~]# rpm -qa|grep ngin
nginx-filesystem-1.20.1-2.el7.noarch
nginx-1.20.1-2.el7.x86_64
Ubuntu系统
查看文件由哪个包提供
用dpkg查看
# 用dpkg -l 过滤
dpkg-l|grep nginx
# 查看安装位置
dpkg -L | grep nginx
find加强
https://blog.csdn/omaidb/article/details/120639101
在系统中查找具有指定特征的文件或者路径
-name 根据文件名进行查找
例如; find -name “.txt" 在当前目录下查找出所有以.txt结尾的文件
-perm
find -perm 775 在当前目录下查找权限是775的所有文件
-user 根据当前用户来,按照文件拥有者查找
find -user 用户名
find -user root
查询属主为root的文件
-nouser 查找没有用户的文件
find -nouser
查询无属主的文件
-group 按照文件所属组进行查找
find -group test3
-type,根据类型来查找
find -type f
f代表文件
find -type d
d代表路径
不想查找用感叹号 !
find ! -type f 不查找文件
等价于find -type d
-exec
系统调用exec是以新的进程去代替原来的进程,但进程的PID保持不变。因此,可以这样认为,exec系统调用并没有创建新的进程,只是替换了原来进程上下文的内容。原进程的代码段,数据段,堆栈段被新的进程所代替。
find -name ".txt” -exec rm -rf {} ;
最后面是分号
find -name “.sql" -exec ls -la {} ;
查找文件名后缀以.sql结尾,的文件的详细信息
{}用来存放前面find出来的结果
find . -name ".txt” -exec cp {} /opt ;
-ok
用法跟exec完全一致,区别在与会询问你是否执行
whereis 命令名
查找系统二进制文件的位置 例如whereis find
which
在系统的环境变量中查找
which python
alias
给命令 取别名 例如:alias la=‘ls -a’
unalias la
一般在~/.bashrc中的alias中添加
添加完执行sourc ~/.bashrc生效
更多推荐
查找Linux系统中某个软件是否安装/存在
发布评论