Linux system rookie essential: how to apply Find command

  

Today, users who want to learn Linux system or just contacted this system are blessed. Today, this tutorial teaches you how to use the Find command. In the system, the command line is very powerful, so usually everyone is better. How many to learn some.

The first is the syntax of find:

find [starting directory] looking for conditional operations

There is also a way of expression: find PATH OPTION [-exec COMMAND { } \\; ]

Because the find command will recursively search for files in the file and its subdirectories based on the options we gave, that is, looking for conditions, so I think this place is “The starting directory” is very good.

The search condition in this command can be a compound condition consisting of logical operators not, and, or. The meanings of the logical operators and, or, not are:

(1) and: logical AND, expressed in the command by “-a”, is the default option of the system, indicating that only the conditions given When both are satisfied, the search for conditions is satisfied. For example:

find –name ’tmp’ –xtype c -user ’inin’

% This command looks for all files that satisfy all three given conditions

(2) or: logical OR, expressed in the command with “-o”. This operator indicates that the search condition is satisfied as long as one of the given conditions is satisfied. For example:

find –name ’tmp’ –o –name ’mina*’

% The command query file name is ’tmp’ or match & rsquo; Mina*’ all files.

(3) not: Logic is not indicated in the command by “!”. This operator indicates that the file that does not satisfy the given condition is found. For example:

find ! –name ’tmp’

% This command queries all files whose file name is not ’tmp’.

It should be noted that when using a lot of logic options, you can bracket these options. In order to avoid the shell itself misunderstanding the parentheses, you need to add the escape character “\\” before the phone number to remove the meaning of the brackets. Example:

find \\(–name ’tmp’ –xtype c -user ’inin& rsquo; \\)

I feel that now I should say the next query condition, The content of the option in find:

In the option, there are specific parameters:

-name & rsquo;string & rsquo; find the file name matches all the files of the given string, string The wildcard characters *, ?, [ ] are available.

-lname ’String & rsquo; Find all symlink files whose filename matches the given string. The wildcards *, ?, [ ] are available in the string.

-gid n Find all files belonging to the user group with ID number n.

-uid n Find all files belonging to a user with ID number n.

-group ’String & rsquo; Find all files belonging to the user group named string.

-user ’String & rsquo; Find all files belonging to the user name given by the string.

-empty Look for a directory or file of size 0.

-path ’String & rsquo; Find all files with the path name matching the given string. The wildcard characters *, ?, [ ] are available in the string.

-perm Permissions Find files and directories with the specified permissions, which can be as 711,644.

-size n[bckw] Finds the file of the specified file size. The characters after n represent the unit. The default is b, which represents a block of 512 bytes.

-type x finds a file of type x, with x being one of the following characters:

Copyright © Windows knowledge All Rights Reserved