From: Migrant Brother’s Technical Road
1. which command
We often want to search for a certain file in Linux, but we don’t know where to put it. You can use some of the following commands to search: The function of the which command is to search for a certain system command in the path specified by the PATH variable. location, but returns the first search result. That is to say, by using the which command, you can see whether a certain system command exists and where the command is executed. 1. Command format: which executable file name 2. Command function: The which command will search for the location of a system command in the path specified by the PATH variable, but return the first search result. 3. Command parameters: 4. Usage examples: Example 1: Find files and display command paths
命令:which lsmod 输出: [root@localhost ~]# which pwd /bin/pwd [root@localhost ~]# which adduser /usr/sbin/adduser [root@localhost ~]#
Explanation: which searches for executable files according to the directory in the PATH variable configured by the user! Therefore, the commands found by different PATH configuration contents are actually different! Example 2: Use which to find out which
Command: whichwhich
Output:
[root@localhost ~]# which whichalias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde' /usr/bin/which [root@localhost ~]#
Explanation: There are actually two which, one of which is alias. This is the so-called "command alias", which means that entering which will be equal to the previous string of commands! Example 3: Find the cd command
Command: whichcd
Output:
Explanation: The commonly used command cd cannot be found! Why? This is because cd is a built-in command in bash! And which by default looks for the directory specified in PATH, so it must not be found!
2. whereis command
The whereis command can only be used to search for program names, and only searches two's complement files (parameter -b), man description files (parameter -m) and source code files (parameter -s). If parameters are omitted, all information is returned. Compared with find, the search speed of whereis is very fast. This is because the Linux system will record all the files in the system in a database file. When using whereis and locate formally introduced below, the data will be searched from the database. Instead of searching by traversing the hard disk like the find command, the efficiency will naturally be very high. Moreover, the database file is not updated in real time. By default, it is updated once a week. Therefore, when we use whereis and locate to search for files, we sometimes find data that has been deleted, or it is difficult to find the file we just created. , the reason is that the database file has not been updated. 1. Command format: whereis[-bmsu][BMS directory name-f] file name 2. Command function: The whereis command locates the location of executable files, source code files, and help files in the file system. The attributes of those files should be original code, two's complement files, or help files. The whereis program also has the ability to search source code, specify alternative search paths, and search for unusual items. 3. Command parameters: 4. Usage example: Example 1: Find all files related to ** file
命令:whereis svn 输出: [root@localhost ~]# whereis tomcat tomcat: [root@localhost ~]# whereis svn svn: /usr/bin/svn /usr/local/svn /usr/share/man/man1/svn.1.gz
Explanation: Tomcat is not installed and cannot be found. The svn installation found many related files. Example 2: Only two's complement files are found
命令:whereis -b svn 输出: [root@localhost ~]# whereis -b svn svn: /usr/bin/svn /usr/local/svn [root@localhost ~]# whereis -m svn svn: /usr/share/man/man1/svn.1.gz [root@localhost ~]# whereis -s svn svn: [root@localhost ~]#
Description: Whereis-msvn finds the path to the documentation document The linux command locates the file , and whereis-ssvn finds the source file.
3. locate command
locate让使用者可以很快速的搜救档案系统内是否有指定的档案。其方式是先构建一个包括系统内所有档案名称及路径的数据库,然后当找寻时就只需查询这个数据库,而毋须实际深入档案系统之中了。在通常的distribution之中,数据库的构建都被置于crontab中手动执行。1.命令格式:Locate[选择参数][式样]2.命令功能:locate命令可以在搜救数据库时快速找到档案linux 命令定位文件,数据库由updatedb程序来更新,updatedb是由crondaemon周期性构建的,locate命令在搜救数据库时比由整个由硬碟资料来搜救资料来得快,但较差劲的是locate所找到的档案若是近来才完善或刚改名的linux串口驱动,可能会找不到,在内定值中,updatedb每晚会跑一次,可以由更改crontab来更新设定值。(etc/crontab)locate指定用在搜救符合条件的档案,它会去储藏档案与目录名称的数据库内,找寻合乎范本式样条件的档案或目录录,可以使用特殊字元(如”*”或”?”等)来指定范本式样,如指定范本为kcpa*ner,locate会找出所有起始字串为kcpa且结尾为ner的档案或目录,如名称为kcpartner若目录录名称为kcpa_ner则会列举该目录下包括子目录在内的所有档案。locate指令和find寻找档案的功能类似linux公社,但locate是透过update程序将硬碟中的所有档案和目录资料先构建一个索引数据库,在执行loacte时直接找该索引,查询速率会较快,索引数据库通常是由操作系统管理,但也可以直接下达update逼迫系统立刻更改索引数据库。3.命令参数:4.使用实例:实例1:查找和pwd相关的所有文件
命令:locate pwd 输出: peida-VirtualBox ~ # locate pwd /bin/pwd /etc/.pwd.lock /sbin/unix_chkpwd /usr/bin/pwdx /usr/include/pwd.h /usr/lib/python2.7/dist-packages/twisted/python/fakepwd.py /usr/lib/python2.7/dist-packages/twisted/python/fakepwd.pyc /usr/lib/python2.7/dist-packages/twisted/python/test/test_fakepwd.py /usr/lib/python2.7/dist-packages/twisted/python/test/test_fakepwd.pyc /usr/lib/syslinux/pwd.c32 /usr/share/help/C/empathy/irc-join-pwd.page /usr/share/help/ca/empathy/irc-join-pwd.page /usr/share/help/cs/empathy/irc-join-pwd.page /usr/share/help/de/empathy/irc-join-pwd.page /usr/share/help/el/empathy/irc-join-pwd.page
实例2:搜索etc目录下所有以sh开头的文件
命令:locate /etc/sh 输出: peida-VirtualBox ~ # locate /etc/sh /etc/shadow /etc/shadow-/etc/shells peida-VirtualBox ~ #
实例3:搜索etc目录下,所有以m开头的文件
命令:locate /etc/m 输出: peida-VirtualBox ~ # locate /etc/m /etc/magic /etc/magic.mime /etc/mailcap /etc/mailcap.order /etc/manpath.config /etc/mate-settings-daemon
想要学习Linux系统运维的同事们可以看一看《Linux系统运维手册从入门到企业实战》这本书,特别适宜Linux学习及工作必备的工具书。
end
良许个人陌陌
添加良许个人陌陌即送3套程序员必看资料
→精选技术资料共享
→高手如云交流社群
本公众号全部博文已整理成一个目录,请在公众号里回复「m」获取!
The above is the detailed content of (Migrant Brother Technology Road) Analysis of command usage examples. For more information, please follow other related articles on the PHP Chinese website!