Frequently Used search commands ------ whereis, which, locate, find, findwhereislocate

Source: Internet
Author: User

Frequently Used search commands ------ whereis, which, locate, find, findwhereislocate

From: http://312788172.iteye.com/blog/730280

We often search for a file in linux, but do not know where it is stored. You can use the following commands to search. These materials are found on the Internet, because they are sometimes not used for a long time. They are often mixed up when used, so they are easy to use here.
Which
Whereis view the file location
View the file location in the locate Database
Find actual search hard disk Query file name

1. which
Syntax:
[Root @ redhat ~] # Which Executable File Name
For example:
[Root @ redhat ~] # Which passwd
/Usr/bin/passwd
Which searches for executable files through the PATH environment variable, so the basic function is to find executable files.

2. whereis
Syntax:
[Root @ redhat ~] # Whereis [-bmsu] file or directory name
Parameter description:
-B: Only binary files are available.
-M: only find the file in the manual path of the instruction file.
-S: only find the source file
-U: file without instructions
For example:
[Root @ redhat ~] # Whereis passwd
Passwd:/usr/bin/passwd/etc/passwd/usr/share/man/man1/passwd.1.gz/usr/share/man/man5/passwd.5.gz
Search out all files related to the passwd file.

[Root @ redhat ~] # Whereis-B passwd
Passwd:/usr/bin/passwd/etc/passwd
Search for binary files only

Compared with find, whereis searches very quickly, because the linux system records all files in the system in a database file, when whereis and the locate described below are used, data will be searched from the database, instead of searching through the hard disk like the find command, which will naturally be very efficient.
However, this database file is not updated in real time. It is updated once a week by default. Therefore, when we use whereis and locate to find the file, we sometimes find the deleted data, or you cannot find the file you just created because the database file is not updated. Therefore, you must update the database file before using it. The command is updatedb.

3. locate
Syntax:
[Root @ redhat ~] # Locate file or directory name
For example:
[Root @ redhat ~] # Locate passwd
/Home/weblogic/bea/user_projects/domains/zhanggongzhe112/myserver/stage/_ export dir_db_war/DB. war/jsp/as/user/passwd. jsp
/Home/weblogic/bea/user_projects/domains/zhanggongzhe112/myserver/stage/_ export dir_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:
[Root @ redhat ~] # Find path parameters
Parameter description:
Time search parameters:
-Atime n: lists the files that have been retrieved from the memory for n * 24 hours.
-Ctime n: lists the files or directories that have been changed or added within n x 24 hours.
-Mtime n: lists the files or directories modified within n x 24 hours.
-Newer file: Lists files that are newer than file.
Name Search parameters:
-Gid n: Find the file whose group ID is n.
-Group name: Find the file with the group name
-Uid n: Find the file whose owner ID is n.
-User name: Find the file whose user name is name
-Name file: searches for files with file names (wildcards can be used)
For example:
[Root @ redhat ~] # Find/-name zgz
/Home/zgz
/Home/zgz
/Home/weblogic/bea/user_projects/domains/zgz
/Home/oracle/product/10g/export toollogs/dbca/zgz
/Home/oracle/product/10g/export toollogs/emca/zgz
/Home/oracle/oradata/zgz

[Root @ redhat ~] # Find/-name '* zgz *'
/Home/zgz
/Home/zgz/zgz1
/Home/zgz/zgzdirzgz
/Home/zgz
/Home/zgz/zgzdir
/Home/weblogic/bea/user_projects/domains/zgz
/Home/weblogic/bea/user_projects/domains/zgz. log00006
/Home/weblogic/bea/user_projects/domains/zgz. log00002
/Home/weblogic/bea/user_projects/domains/zgz. log00004
/Home/weblogic/bea/user_projects/domains/zgz. log
/Home/weblogic/bea/user_projects/domains/zgz. log1_8
/Home/weblogic/bea/user_projects/domains/zgz. log00005

When we use whereis and locate to find the files we need, we can use find, but find is to traverse and query the files on the hard disk, which consumes a lot of hard disk resources, and the efficiency is very low. Therefore, we recommend that you prioritize whereis and locate.
Locate is used for searching in the database. The database is updated every day.
Whereis can find executable commands and man page
Find is to find files based on conditions.
Which can find executable files and aliases (alias)

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.