(1). example

1. List all the files in the current directory and subdirectories .txt file

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

[[email protected] ~]$ ls

1.txt  3.txt  b.txt  public   video   file   music

2.txt  a.txt  c.txt  Templates   picture   download   desktop

[[email protected] ~]$ find . -name "*.txt"

]./.cache/tracker/db-version.txt

./.cache/tracker/db-locale.txt

./.cache/tracker/parser-sha1.txt

./.cache/tracker/locale-for-miner-user-guides.txt

./.cache/tracker/locale-for-miner-apps.txt

./.cache/tracker/last-crawl.txt

./.cache/tracker/first-index.txt

./1.txt

./2.txt

./3.txt

./a.txt

./b.txt

./c.txt

2. Find the change time of the current user within one day or more .txt file

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

[[email protected] ~]$ find . -mtime -1 -name "*.txt" // Within a day

./.cache/tracker/locale-for-miner-user-guides.txt

./.cache/tracker/locale-for-miner-apps.txt

./1.txt

./2.txt

./3.txt

./a.txt

./b.txt

./c.txt

[[email protected] ~]$ stat 1.txt

   file :"1.txt"

   size :0          block :0          IO block :4096   Ordinary empty file

equipment :803h/2051d   Inode:52016194    Hard links :1

jurisdiction :(0664/-rw-rw-r--)  Uid:( 1000/      xf)   Gid:( 1000/      xf)

Environmental Science :unconfined_u:object_r:user_home_t:s0

Recently visited :2019-03-04 15:33:04.998746697 +0800

Recent changes :2019-03-04 15:33:04.998746697 +0800

Recent changes :2019-03-04 15:33:04.998746697 +0800

Creation time :-

[[email protected] ~]$ find . -mtime +1 -name "*.txt" // More than a day

./.cache/tracker/db-version.txt

./.cache/tracker/db-locale.txt

./.cache/tracker/parser-sha1.txt

./.cache/tracker/last-crawl.txt

./.cache/tracker/first-index.txt

[[email protected] ~]$ stat ./.cache/tracker/db-version.txt

   file :"./.cache/tracker/db-version.txt"

   size :2          block :8          IO block :4096   Ordinary documents

equipment :803h/2051d   Inode:35360       Hard links :1

jurisdiction :(0644/-rw-r--r--)  Uid:( 1000/      xf)   Gid:( 1000/      xf)

Environmental Science :unconfined_u:object_r:cache_home_t:s0

Recently visited :2019-03-04 10:05:12.993515697 +0800

Recent changes :2018-09-06 11:43:45.770953885 +0800

Recent changes :2018-09-06 11:43:45.770953885 +0800

Creation time :-

3. Execute the corresponding command on the search content

1

2

3

4

5

6

7

8

9

10

11

12

13

exi ~]$ touch {1,2,3}.back

[[email protected] ~]$ find . -name "*.back"

./1.back

./2.back

./3.back

[[email protected] ~]$ find . -name "*.back" -exec ls -l {} \;

-rw-rw-r--. 1 xf xf 0 3 month    4 18:39 ./1.back

-rw-rw-r--. 1 xf xf 0 3 month    4 18:39 ./2.back

-rw-rw-r--. 1 xf xf 0 3 month    4 18:39 ./3.back

[[email protected] ~]$ ls -l ./1.back;ls -l ./2.back;ls -l ./3.back;    // Split execution

-rw-rw-r--. 1 xf xf 0 3 month    4 18:39 ./1.back

-rw-rw-r--. 1 xf xf 0 3 month    4 18:39 ./2.back

-rw-rw-r--. 1 xf xf 0 3 month    4 18:39 ./3.back

4. And xargs -i A combination of ,find Instead of the result of {}

1

2

3

4

[[email protected] ~]$ find . -name "*.back" | xargs -i ls -l {}

-rw-rw-r--. 1 xf xf 0 3 month    4 18:39 ./1.back

-rw-rw-r--. 1 xf xf 0 3 month    4 18:39 ./2.back

-rw-rw-r--. 1 xf xf 0 3 month    4 18:39 ./3.back

5. Find multiple types of files

1

2

3

4

5

6

7

8

9

[[email protected] ~]$ touch a.pdf

[[email protected] ~]$ find . -name "*.back" -o -name "*.pdf" //-o perhaps , It can also be written as -or

./1.back

./2.back

./3.back

./a.pdf

[[email protected] ~]$ find . -size +20k -a -size -30k //-a also , It can also be written as -and

./.config/pulse/93c68f6a5c7b462db558e8e995b4212a-card-database.tdb

./.local/share/evolution/addressbook/system/contacts.db

6. Search by permission

1

2

3

4

5

6

7

8

9

10

11

12

13

14

[[email protected] ~]# mkdir aaa

[[email protected] ~]# mkdir bbb

[[email protected] ~]# touch a.sh

[[email protected] ~]# chmod 777 aaa

[[email protected] ~]# chmod 1777 bbb

[[email protected] ~]# chmod 4777 a.sh

[[email protected] ~]# find /root/ -perm 777 // Permission is 777 All the files or folders of

/root/aaa

[[email protected] ~]# find /root/ -perm -777 // Permission is at least 777 All the files or folders of

/root/aaa

/root/bbb

/root/a.sh

[[email protected] ~]# find /root -type f -perm -777 // Permission is at least 777 All the ordinary documents of .-type f Specify the normal file

/root/a.sh

7. Find directory depth

1

2

3

4

5

6

7

8

9

10

11

12

13

14

[[email protected] ~]# find /bin -maxdepth 1 -perm -755 //bin There is no /, that bin For the first floor

/bin

[[email protected] ~]# find /bin/ -maxdepth 1 -perm -755 //bin After the /, The next level is the first level

/bin/cp

/bin/lua

/bin/captoinfo

/bin/csplit

/bin/clear

/bin/cut

/bin/luac

/bin/infocmp

/bin/fmt

/bin/unxz

// More , Just part of it

8. Find all that belong to the user xf The file of , And copy to the specified directory

1

2

3

4

5

6

7

8

9

10

[[email protected] ~]# mkdir findresults

[[email protected] ~]# ls

1.txt            core.3160    initial-setup-ks.cfg  Templates   picture   download   desktop

anaconda-ks.cfg  findresults  public                   video   file   music

[[email protected] ~]# find / -user xf -exec cp -a {} /root/findresults/ \;

find: ‘/proc/11379/task/11379/fd/5’: There is no file or directory

find: ‘/proc/11379/task/11379/fdinfo/5’: There is no file or directory

find: ‘/proc/11379/fd/6’: There is no file or directory

find: ‘/proc/11379/fdinfo/6’: There is no file or directory

cp: Can't use directory "/home/xf"  To override the non Directory "/root/findresults/xf"

There is no problem with the above command , This involves files and files in the same directory 、 Folder and folder , Neither file nor folder can have the same name .Windows Files and folders can have the same name because they have extensions , Otherwise, we can't have the same name .

At this time, we can temporarily change the file name , So that we can continue with

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

[[email protected] ~]# mv /var/spool/mail/xf /var/spool/mail/xf.mail // Change the file name temporarily

[[email protected] ~]# rm -rf /root/findresults/* // Empty the original copy file

[[email protected] ~]# find / -user xf -exec cp -a {} /root/findresults/ \; // Re execution

find: ‘/proc/12438/task/12438/fd/5’: There is no file or directory

find: ‘/proc/12438/task/12438/fdinfo/5’: There is no file or directory

find: ‘/proc/12438/fd/6’: There is no file or directory

find: ‘/proc/12438/fdinfo/6’: There is no file or directory

cp: "/root/findresults/.esd-1000"  And "/root/findresults/.esd-1000"  For the same document

cp: "/root/findresults/.mozilla"  And "/root/findresults/.mozilla"  For the same document

cp: "/root/findresults/.bash_logout"  And "/root/findresults/.bash_logout"  For the same document

cp: "/root/findresults/.bash_profile"  And "/root/findresults/.bash_profile"  For the same document

cp: "/root/findresults/.bashrc"  And "/root/findresults/.bashrc"  For the same document

cp: "/root/findresults/.cache"  And "/root/findresults/.cache"  For the same document

cp: "/root/findresults/.changed"  And "/root/findresults/.changed"  For the same document

cp: "/root/findresults/.dbus"  And "/root/findresults/.dbus"  For the same document

cp: "/root/findresults/.config"  And "/root/findresults/.config"  For the same document

cp: "/root/findresults/.ICEauthority"  And "/root/findresults/.ICEauthority"  For the same document

cp: "/root/findresults/.local"  And "/root/findresults/.local"  For the same document

cp: "/root/findresults/.esd_auth"  And "/root/findresults/.esd_auth"  For the same document

cp: "/root/findresults/.bash_history"  And "/root/findresults/.bash_history"  For the same document

cp: "/root/findresults/.lesshst"  And "/root/findresults/.lesshst"  For the same document

cp: "/root/findresults/.viminfo"  And "/root/findresults/.viminfo"  For the same document

[[email protected] ~]# mv /var/spool/mail/xf.mail /var/spool/mail/xf // Finally, change it back

[[email protected] ~]# ls /var/spool/mail/

root  rpc  xf