Which,whereis,locate,find

Source: Internet
Author: User

We often find a file in Linux, but we do not know where to put it, you can use some of the following commands to search. These are the information found from the Internet, because sometimes it is not used for a long time, when the use of the time is often confused, so it is easy to use here.
Which viewing the location of an executable file
Whereis viewing the location of a file
Locate to view file locations with a database
Find actual search hard disk query file name

[Email protected] admin]# Find/u02/app/oracle-name utlmatch.sql-print
/u02/app/oracle/rdbms/admin/utlmatch.sql
[Email protected] admin]# Find/u02/app/oracle-name utlmatch.sql
/u02/app/oracle/rdbms/admin/utlmatch.sql

1, which
Grammar:
[[email protected] ~]# which executable file name
For example:
[email protected] ~]# which passwd
/usr/bin/passwd
Which is to find the executable file through the PATH environment variable to that route, so the basic function is to find the executable file

2, Whereis
Grammar:
[[email protected] ~]# Whereis [-bmsu] file or directory name
Parameter description:
-B: Only binary files are found
-M: Only files found under the manual path of the description file
-S: Find source files only
-u: File without document description
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 associated with the passwd file

[Email protected] ~]# whereis-b passwd
passwd:/usr/bin/passwd/etc/passwd
Only binary files are found

Whereis looks very fast compared to find, because the Linux system records all the files in the system in a single database file, and when you use Whereis and the locate described below, the data is looked up from the database, not like the Find command, By traversing the hard drive to find, the efficiency will naturally be very high.
However, the database file is not updated in real time and is updated once a week by default, so when we use Whereis and locate to find files, we sometimes find data that has been deleted, or just created the file, but cannot find it because the database file is not updated.

3, locate
Syntax:
[[email protected] ~]# locate file or directory name
For example:
[[email protected] ~]# Locate PASSW D
/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
Syntax:
[[email protected] ~]# Find Path parameter
Parameter description:
Time lookup parameter:
-atime N: List files accessed within n*24 hours
-ctime N: List the files or directories that are changed within n*24 hours
-mtime N: List files or directories that have been modified in n*24 hours
-newer file: List the files that are newer than document
name lookup parameters:
- GID N: Looking for a file with group ID n
-group name: Looking for a file with the name of the group
-uid N: Looking for a file with owner ID n
-user name: Find a file with the user name called name
-name : Look for files named file (wildcard characters can be used)
For example:
[[email protected] ~]# Find/-name zgz
/home/zgz
/home/zgz/zgz
/ho Me/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 can't find the files we need with Whereis and locate, we can use find, but find is traversing lookups on the hard disk, so it consumes hard disk resources and is very inefficient, so it is recommended that you use Whereis and locate first.
Locate is found in the database, and the database is updated as large as daily.
Whereis can find executable commands and man page
Find is finding files based on criteria.
which can find executable files and aliases (alias)

Which,whereis,locate,find

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.