Linux中搜索命令(locate,which,whereis,grep)

Linux中搜索命令(locate,which,whereis,grep)

locate 通过系统的文件资料库库搜索

语法: locate [filename]
		-i 不区分大小写
//注意事项:1. 系统资料库不定时更新,如果没有更新,需要手动更新使用updatedb命令
		  2./tmp目录下的文件不被文件资料库统计所以无法使用locate搜索
eg: [root@localhost ~]# locate h1
	/root/h1
	/root/h1/h5
//如果使用Locate命令时提示
		-bash: locate: command not found则表示本机未安装locate
//只需yum install mlocate安装即可

which 搜索名令的位置

which [命令名称] //搜索命令所在位置(可查看命令所处路径和别名)
eg: [root@localhost ~]# which ls
	alias ls='ls --color=auto'
		/usr/bin/ls

whereis 搜索命令和帮助文档位置

eg:[root@localhost ~]# whereis ls
	ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz

grep 搜索某内容在某文件内的位置

语法:grep [搜索内容][待搜索文件]
	-i 忽略大小写
	-v 排除包含某内容的行
eg:	// 搜索/etc/inittab文件中的排除以'#'开头行的内容
	[root@localhost ~]# more /etc/inittab
	# inittab is no longer used when using systemd.
	#
	# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
	#
	# Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target
	#
	# systemd uses 'targets' instead of runlevels. By default, there are two main targets:
	#
	# multi-user.target: analogous to runlevel 3
	# graphical.target: analogous to runlevel 5
	#
	# To view current default target, run:
	# systemctl get-default
	#
	# To set a default target, run:
	# systemctl set-default TARGET.target
	#
	hello
	[root@localhost ~]# grep -v ^# /etc/inittab
	hello
发布了27 篇原创文章 · 获赞 7 · 访问量 1090

猜你喜欢

转载自blog.csdn.net/qq_36917605/article/details/104076622