turn from: http://312788172.iteye.com/blog/730280
We often find a file in Linux, but I do n’t know where to put it. You can use some of the following commands to search. These are the information found online, because sometimes they are not used for a long time, and they are often confused when used, so put it here for easy use.
Which View position of the executable file
WHEREIS View the location of the file
LOCATE match database View file location
Find Actual search hard disk query file name
1、which
grammar:
[[email protected]~] #Thich executable file name
for example:
[[email protected] ~]# which passwd
/usr/bin/passwd
Which is to find executable files through the PATH environment variables, so the basic function is to find executable files
2、whereis
grammar:
[[email protected]~] #Whereis [-bmsu] file or directory name
Parameter explanation:
-b: Just find binary files
-m: Find the file under the explanation file Manual path
-S: Just find Source source files
-U: No file of the documentation
For example:
[[email protected] ~]# whereis passwd
passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man1/passwd.1.gz /usr/share/man/man5/passwd.5.gz
Find the files related to the passwd file
[[email protected] ~]# whereis -b passwd
passwd: /usr/bin/passwd /etc/passwd
Only find binary files
Compared with Find, whereis is looking for very fast, because the Linux system will record all the files in the system in a database file. When using WHEREIS and the Locate will be introduced below, they will be found from the database. Data, instead of finding through the hard disk like the Find command, will naturally be very efficient.
But the database file is not updated in real time, and it is updated once a week by default. Therefore, when we use WHEREIS and Locate to find files, we sometimes find the data that has been deleted, or the file has just been established, but it cannot be found. The reason is that the database file is not updated.
3、 locate
grammar:
[[email protected]~]# local file or directory name
Example such as:
[[email protected] ~]# locate passwd
/home/weblogic/bea/user_projects/domains/zhanggongzhe112/myserver/stage/_appsdir_DB_war/DB.war/jsp/as/user/passwd.jsp
/home/weblogic/bea/user_projects/domains/zhanggongzhe112/myserver/stage/_appsdir_admin_war/admin.war/jsp/platform/passwd.jsp
/lib/security/pam_unix_passwd.so
/lib/security/pam_passwdqc.so
/usr/include/rpcsvc/yppasswd.x
/usr/include/rpcsvc/yppasswd.h
/usr/lib/perl5/5.8.5/i386-linux-thread-multi/rpcsvc/yppasswd.ph
/usr/lib/kde3/kded_kpasswdserver.la
/usr/lib/kde3/kded_kpasswdserver.so
/usr/lib/ruby/1.8/webrick/httpauth/htpasswd.rb
/usr/bin/vncpasswd
/usr/bin/userpasswd
/usr/bin/yppasswd
…………
4、 find
grammar:
[[email protected]~]# Find path parameters
Parameter description:
Time search parameters:
-atime n: List the files accepted within 24 hours of N*24 hours
-Ctime n: Change the N*24 -hour change and new file or directory list
-mtime n: Put out the files or directory modified within N*24 hours
-Newer File: List the new file that is more new than file
Name search parameter:
-gid n: Find a file with a group ID to N
-group name: Find a file with group name name
-UID N: Find a file with an owner ID to N
-User Name: Files looking for user names name name
-Name File: Find a file named file file (you can use the passing symbol)
Example such as:
[[email protected] ~]# find / -name zgz
/home/zgz
/home/zgz/zgz
/home/weblogic/bea/user_projects/domains/zgz
/home/oracle/product/10g/cfgtoollogs/dbca/zgz
/home/oracle/product/10g/cfgtoollogs/emca/zgz
/home/oracle/oradata/zgz
[[email protected] ~]# find / -name ‘*zgz*’
/home/zgz
/home/zgz/zgz1
/home/zgz/zgzdirzgz
/home/zgz/zgz
/home/zgz/zgzdir
/home/weblogic/bea/user_projects/domains/zgz
/home/weblogic/bea/user_projects/domains/zgz/zgz.log00006
/home/weblogic/bea/user_projects/domains/zgz/zgz.log00002
/home/weblogic/bea/user_projects/domains/zgz/zgz.log00004
/home/weblogic/bea/user_projects/domains/zgz/zgz.log
/home/weblogic/bea/user_projects/domains/zgz/zgz.log00008
/home/weblogic/bea/user_projects/domains/zgz/zgz.log00005
When we cannot find the files we need with whereis and local, we can use Find, but Find traverses on the hard disk, so it consumes the resources of the hard disk and the efficiency is very low. Therefore Locate.
Locate is found in the database, and the database is updated once a day.
Whereis can find executable commands and Man Page
Find is to find files according to the conditions.
Which can find executable files and alias (alias)