The Find command in Linux uses some attention point collation

Source: Internet
Author: User
Tags root directory

The Find command uses the-path parameter, the filename is a matching shell wildcard pattern. At this point, the meta character does not recognize '/' and '. ' 。 As an example

Suppose there are four files in the/root directory, and the absolute path is:

The code is as follows:

/root/src/misc

/root/src/test/misc

/root/src1misc

/root/test/src/misc

Enter the following command:

The code is as follows:

[Root@dabu.info ~]# Cd/root

[Root@dabu.info ~] #find. -path './sr*sc '

./src1misc

./src/misc

./src/test/misc

The result of the command run output is not the file name, but the path to the file

Visible, folder symbols/can also be matched with * wildcard characters at this time, and * can match n multiple characters. The command line above means a file that matches the path of the file in the current directory and subdirectories recursively, so the path to the file is output.

Because it is './sr*sc ', so/root/test/src/misc this file does not match because./represents the current directory (that is,/root), and/root/test/src/misc does not conform to the./sr format.

But slightly changed, as follows:

The code is as follows:

[Root@dabu.info ~] #find. -path ' */sr*sc* '

./src1misc

./src/misc

./src/test/misc

./test/src/misc

Explanation: Because "*" can match "." and "/", we change the ' */sr*sc* ' above to ' *sr*sc* '. The result is the same.

Note: You can also use absolute paths directly

The code is as follows:

[Root@dabu.info ~] #find/root-path ' */sr*sc* '

and

The code is as follows:

[Root@dabu.info ~] #find/root-path '/root/sr*sc* '

/root/src1misc

/root/src/misc

/root/src/test/misc

At this point,/root/test/src/misc is inconsistent with the '/root/sr*sc* ' format.

So Linux/unix: The way to recursively find and list all (all) hidden files can be as follows:

The code is as follows:

[Root@dabu.info ~] #find/To find the text/pieces/folder/-path ' */.* '-print

Finish the Tutorial!

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.