Linux base (5) - search for files
Search-related commands commonly used are whereis
, which
, find
and locate
.
- whereis simple and fast
$ whereis who
$ whereis find
whereis find
Found 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 . whereis
Only 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 locate
command.
- 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 updatedb
command updated, so sometimes you just add a file, it may find You not need to manually perform a updatedb
command (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 -c
parameters, -i
parameters can ignore case to find, whereis of -b
, -m
, -s
can also be used.
- which a small but
which
Shell itself is a built-in command, we usually use which
to determine whether a given software installation, because it only from PATH
the specified environment variable to the path search command:
$ which man
- find fine and fine
find
These 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. find
Strong 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 -mtime
parameters 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
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