Article Title: describes how to find files in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source. There are several search commands in Linux. I usually use whereis and find. Here I will share with you.
Whereis
Whereis is mainly used to find command files, source code, and man help files. It is also very easy to use, such
// Find the Help File [Wyg @ server] # whereis-m php:/usr/share/man/man1/php.1 // Search for binary files, which are all listed in addition to the Help File [Wyg @ server] # whereis-B php:/usr/bin/php/etc/php. d/etc/php. ini/usr/include/php // The Source Code cannot be found ~~ [Wyg @ server] # whereis-s php Php: |
That's enough. It's enough.
Find
The find command is more powerful than him, mainly because of its strong customization. It is invincible to execute commands with other commands. In terms of server management, it is especially nice to operate on specific log files.
Usage:
Find the directory restriction-exec command to be executed {}\; |
There are many restrictions, which can be used in combination. Below are some common
Mtime + 90 indicates that it was modified 90 days ago (+ indicates that it was before that day,-indicates that it was after that day, and no symbol indicates that it was exactly that day)
Atime + 90 indicates that
Type f indicates a common file
Type d indicates a directory.
Perm 744 indicates that the File Permission is 744
Size + 512 k indicates that the file is larger than 512 k
The command to be executed depends on yours. For example, to list the commonly used ls-l-h directory, use it directly. This is the same as normal, note that the {} will be replaced with the found file name. Therefore, if you want to execute the command to pay attention to the location of the file name, adjust the location.
In addition, if you replace-exec with-OK, you need to confirm the operation to be performed. This is good for deleting files. If you delete the files by mistake, the problem will be big. Are you right.
A few examples are provided for your reference. In case of problems, you can directly call "man" on the command line. Linux really makes sense. Even if a man is suffering, he must know everything about it. Really bitter, run a command:
[Wyg @ server] # man woman No manual entry for woman |
Example:
1. Search for files that have been modified for more than 90 days
# Find/data/users-mtime + 90
2. Search for files earlier than 90 days ago and use LS to list the full names
# Find/data/users-mtime + 90-type f-exec ls-l-h {}\;
3. Search for files that have been modified for more than 90 days and do not contain the click_15 and click_16 directories.
# Find/data/users-mtime + 90 (-path/data/users/click_15-o-path/data/users/click_16) -prune-o-print
4. The search and modification time exceeds 90 days, and you need to confirm the deletion
# Find/data/users-mtime + 90-OK rm-R {}\.