Reproduced Search file commands in Linux

Source: Internet
Author: User

Search files are very useful, we often need to know where a file is stored, and we know that Linux is a powerful command system, so there are a lot of very good search commands. Often find is not used, because it is slow and consumes hard disk space. Usually we use Whereis or locate to check, and if we can't find it, we'll search by find. Why is it? Because Whereis locate is using a database to search for data, it is quite fast, and is not a few searches of hard disks, compared to time-saving.

1.which (Look for "Execute File"), which followed by executable file name if you add-a at the end, you can find all execution files with the same name instead of just one. This command searches for the file name of the "execute file" according to the path that is regulated by the "path" environment variable, so the focus is to find the "Execute file". 2.whereis (looking for a specific file) Why is Whereis faster than the find search? Because the Linux system will record all the files in the system in a database file, when using Whereis or locate, will be based on the contents of this database, so, sometimes, you will also find that when using the two executable files, will find the deleted files, And you can't find the latest file you just created. This is because these two commands are searched for files through the results in the database. Linux every day for the location of all the files on the Linux host, search database updates, the updated program is the use of updatedb.3.locate more simple, directly after the "file part name", you can get results. 4.find is a very powerful command. If you are looking for a file, using find is a good idea. It can be based on different parameters to provide search function, for example, to find files named httpd.conf file, he should be in/etc, you can use "Find  /etc  -name httpd.conf", If you remember that there is a file filename containing the httpd.conf file, but do not know the full name, you can use wildcards *, such as "Find  /etc  -name   ' *httpd '" can be file names containing httpd files are listed, However, because find is quite draining the hard disk when looking for data, it is generally not to use find, there is a better command to replace it, that is Whereis and locate.  example: the past 24 hours on the system changed the contents of the file listed: Find  /  -mtime  0, where 0 is the focus, 0 represents the current time, so, from now to 24 hours ago   Example Two: Find/etc files below if the file date is newer than/etc/passwd: Find  /etc  -newer  /etc/passwd  Example Three: Search for files belonging to/home under Dmtsai: Find  /home  -user  dmtsai  Example four: Search the system for files that do not belong to anyone: find / -nouser, through this command, it is easy to find the less normal I see, if you find a file that does not belong to anyone in the system, do not be too nervous, sometimes normal. Especially if you compile the software yourself with the source code.   Example five: finding files named passwd: Find  / -name  passwd  example six: Search files that contain sgid/suid/sbit attributes: Find  /  -perm  +70007000 is---s--s--t, as long as the list contains s or T, so add 7000  example seven: The file found in the example above is listed using ls-l: Find  /  Perm  + 7000  -exec ls-l  {} \; The command behind-exec is an extra command, {} means "something found in Find", so-exec ls-l {} is a list of the file details found earlier. -exec at last must take \;   Example eight: Find files larger than 1MB in the system: Find  / size  +1000K  reprinted from: http://blog.chinaunix.net/ Uid-26983585-id-3391759.html

[Reprint] The search file command in Linux

Related Article

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.