当前位置:网站首页>How to use the find command

How to use the find command

2022-06-25 22:29:00 David Cao

purpose

find The command is used to find files in the specified directory .

Full name

nothing

Parameters

-name : Followed by the file name pattern that needs to be matched , You need to use quotation marks

Here are some simple examples to find :(~ Express $HOME Catalog )

1. Find the current $HOME Next '.log' Final document

find ~ –name "*.log" –print

2. Find all under the current directory and subdirectories '.log' Final document

find . –name "*.log" –print

3. Find the files whose file names begin with a capital letter under the current directory and subdirectories

find . –name "A-Z" –print

4. stay /etc Find the file name in the directory to host Opening file

find /etc –name "host*" –print

5. Find a file name in the current directory that begins with a lowercase letter , And finally 4 To 9 add .txt The closing document

find . –name "a-z*4-9.txt" –print

find file by name

-iname : Find the file by its name , Case insensitive

1. Find the file name .log Final document , Case insensitive

find . –iname "*.log" –print

-perm : Followed by file permissions , Find files by file permission mode

1. Find the file permissions in the current directory 777 The file of

find . –perm 777 –print

how to Find file in Linux

-prune : Ignore a directory

1. Hope that in tmp The lookup , But I don't want to be in /tmp/tmp1 The lookup

find test –path "/tmp/tmp1" –prune –o –print

2. Hope that in tmp The lookup , But I don't want to be in /tmp/tmp1、/tmp/tm2、/tmp/tmp3 Wait for multiple folders to find

find test (–path tmp/tmp1 –o –path tmp/tmp2 –o –path tmp/tmp2 ) –prune –o –print

-user And nouser : Search and find the file whose master account has been deleted according to the file owner

1. Find file owner as qinys All files for

find ~ –user qinys –print

2. Find and delete users Tom The file of

find /home –nouser –print

-group And nogroup : Find and search the deleted files belonging to the user group according to the user group to which the file belongs

1. Find file owner as qinys All files for

find ~ –group gp1 –print

2. Find and delete users Tom The file of

find /home –nogroup –print

-mtime\atime\ctime : Find the file according to the change time or access time

1. Find the change time in the root directory at 5 Documents within days

find / –mtime -5 –print

2. lookup /home Under the table of contents 3 Documents of the past

find / –mtime +3 –print

10 Linux find exec examples

-newer : Look for all files that have changed more recently than one file but are older than another

grammar :new\_file\_name ! old\_file\_name

among ! It's logical and non symbolic

1. Find change time than file a.log new , But it's more than a file b.log Old documents ( If it is in the directory now /home Next )

find –newer a.log ! -newer b.log

2. Find change time ratio tmp.log New files

find . –newer tmp.log

-size : Find files based on file size ( The file length here can be measured in blocks , Bytes can also be used to measure )

1. Find the file in the current directory whose length is greater than 1M Byte file

find . –size +1000000c –print

2. In the catalog /home The length of the next search file is exactly 100 Byte file

find . –size 100c –print

3. The search length in the current directory exceeds 10 Block file ( A piece is equal to 512 byte )

find . –size +10 –print

-type : Find a type of file , Such as :

b - Block device file .

d - Catalog .

c - Character device file .

p - Pipeline files .

l - Symbolic link file .

f - Ordinary documents .

Case study

1. Find the change time in the directory at 6 Days ago and delete them ( notes : It's today 20190109)

2. Find the change time in the directory at 1 The suffix before the day is .log And delete them , Prompt when deleting

20 advanced Linux find Examples

find exec rm command to delete files

find files in linux with find command examples

原网站

版权声明
本文为[David Cao]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202181043145218.html

随机推荐