Linux base (5) - search for files

Linux base (5) - search for files

Search-related commands commonly used are whereis, which, findand locate.

  • whereis simple and fast
$ whereis who
$ whereis find

whereis findFound the three paths, two executable path and the path where a man online help file, the search quickly, because it does not look in turn from the hard disk, but directly from the database query . whereisOnly search binary (-b), man Help file (-m) and source code files (-s). If you want a more comprehensive search results can be obtained using the locatecommand.

  • locate fast and full

By " /var/lib/mlocate/mlocate.db " database lookups, but this database is not updated in real time, the system will perform an automatic daily scheduled tasks using updatedbcommand updated, so sometimes you just add a file, it may find You not need to manually perform a updatedbcommand (you must execute the command once in our environment). It can be used to find different types of files in the specified directory, such as finding all the files that start with sh / etc:

$ sudo apt-get update
$ sudo apt-get install locate
$ locate /etc/sh

Note that it does not just look in the / etc directory and subdirectories will automatically recursive lookup.

Find / usr / share / all jpg files:

$ locate /usr/share/\*.jpg

Note To add an asterisk in front of the backslash escape, otherwise it will not be found.

If you want to count the number can add -cparameters, -iparameters can ignore case to find, whereis of -b, -m, -scan also be used.

  • which a small but

whichShell itself is a built-in command, we usually use whichto determine whether a given software installation, because it only from PATHthe specified environment variable to the path search command:

$ which man
  • find fine and fine

findThese orders should be the most powerful, and it is not only possible but also can search on attributes (such as timestamps of files, file permissions, etc.) to find files by file type, file name. findStrong enough to command, it should at least understand the need to speak several separate lesson for the job, we only introduce some common content.

This command indicates to the / etc / directory, search interfaces called the name of the file or directory. This is the most common form of the find command, the first argument must remember find a place to search:

$ sudo find /etc/ -name interfaces

Note that the find command path as the first parameter, the basic command format to find [path] [option] [action].

Command time-related parameters:

parameter Explanation
-atime The last access time
-ctime The last time modify the file contents
-mtime The last time modify the file attributes

In the following -mtimeparameters for example:

  • -mtime n: N is a number, expressed as modified in the previous n days "within a day" file
  • -mtime +n: List been modified n days before the (n days does not include per se) file
  • -mtime -n: Listed in n days (days itself comprising n) are modified file.
  • -newer file: File to an existing file, the file is newer than the list of file names

img

Lists the home directory, the same day (within 24 hours) changed files:

$ find ~ -mtime 0

Listed in the user's home directory than the new file folder Code:

$ find ~ -newer /home/shiyanlou/Code
Published 76 original articles · won praise 30 · views 5843

Guess you like

Origin blog.csdn.net/weixin_45926367/article/details/104661562