The fourth day of Linux study notes - common find commands

find

1 Find by name

Fixed name search (case sensitive): find location-name name.

eg:find /tmp -name clj                                                   

After the execution is completed, clj under /tmp is found

Fixed name search (case insensitive): find location - iname name.

eg:find /tmp -iname clj                                           

Once executed, all files and directories will be found case insensitive

Wildcard lookup: use * and ? to find

eg: find /tmp -name clj*

* represents the left and right characters, this command is to find all files and directories starting with clj. Also, can you use ? to make a query, such as: find /tmp -name clj? ? It means that the file or directory to be searched starts with clj, and there are two more digits behind it that you don't know what it is. several? There are a few behind the representative.

2 Find by size

find position -size +-= file size. + means greater than, - means less than, = means equal to

eg: find /tmp -size + 2048. This means finding files or directories larger than 1M under /tmp. Some people will ask, shouldn't it be 2M? In fact, in this command, the size of the file is calculated according to the data block, 1 data block=0.5k, and 1M=1024k, 1024k is 2048 data blocks. Therefore, if you want to find a file or directory larger than 1M, the command to be executed is find /tmp -size + 2048. Similarly, the minus sign and the equal sign are the same.

3 Find by owner and group

find /home -user owner (group) name

eg: find /home -user clj. This command is to find files and directories whose owner is clj

eg: find /home -group clj. This command is to find the files and directories that belong to the group clj

4 Find by time attribute

find position -amin,-cmin,-mmin +-time

-amin +- time A minus sign means that the file has been viewed within a certain period of time, and a plus sign means that the file has been viewed before a certain period of time. eg:find /tmp -amin +5 means to find the file or directory that was browsed five minutes ago under tmp
-cmin +-time The minus sign means that the file attributes have been modified within a certain period of time (the ones you can see with the ls command) , and the plus sign means that the file has been modified before a certain period of time eg:find /tmp -cmin +5 means to find files or directories whose attributes have been modified five minutes ago under tmp
-mmin +-time The minus sign means that the content of the file (that is, the content in the file) has been modified within a certain period of time, and the plus sign means that it has been modified before a certain period of time eg:find /tmp -mmin -5 means to find files or directories whose content has been modified within five minutes under tmp

5 Find according to i-node

find location - inum i node number. eg:find /tmp -inum 522243 means you want to find the file or directory whose i-node number is 522243 under tmp

6 Find by Type

find location-type fdl : f represents a file, d represents a directory, and l represents a soft link.

eg: find /tmp -type f means to find files under tmp

7 Conditional parallel search

find location condition 1 -o -a condition 2, -a means both conditions are met, -o means only one condition is met.

eg: find /tmp -type f -a -name clj* means to find the file whose name starts with clj under tmp (because it is f, it will not search the directory, only the file).

8 Find and operate

Sometimes, when you find a file or directory, you want to modify it immediately, instead of going to that directory or typing the command again to modify it after you find it, then we need to use -ok or -exec command

Format: find position condition -exec(-ok) operation {} \;

eg: find /tmp -name clj* -a -type f -exec cat {} \;  the red part can be regarded as a fixed format

This command is to find the file starting with clj under tmp and browse the content. Of course, -exec can also be replaced by -ok, but -ok will have a prompt.

ok, finish work! ! !

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326995337&siteId=291194637