Linux find articles

Reprinted connection: https://blog.csdn.net/weixin_41476978/article/details/88076058

 

A: find Command Overview

linux find command to find the file in the specified directory. Any string parameters located before will be considered directory name you want to find

If you use the command, do not set any parameters, the find command will find subdirectories and files in the current directory. And will look into all the subdirectories and files are displayed

1 find  path  -option   [   -print  ]  [   -exec  -ok   command   ]  {}   \;

1, the processing operation

- Print: Print to the screen
 - LS: find files for LS
 - the Delete: Delete the found files
 - the ok command {} \; execute the command designated by the command of the file search, interactive
 - Exec command {} \; Ibid., non-interactive 
{}: in front of the file name find representatives found themselves 
such as: 
. find / the -type f -exec cp .bak {} \; will look for the files are copied to a .bak file

2, according to the owner, is a set of lookup

- the User username: Find owner is xx files
 - Group Group: Find is a group of xx file
 - uid useruid: Find uid number of documents
 - gid groupId: Find gid number of documents
 - nouser: Finding no owner of the file, that is, user file exists but has been deleted
 -nogroup: Find files do not belong to the group

3, depending on the file type to find

- type F: normal file
 - type D: Directory File
 - type L: symbolic link file
 - type S: socket file
 - type B: block device file
 - type C: character device file
 -type p: pipe file

4, according to the size Find

-size + 1OM: greater than 10m file
 -size + 10K: the file is larger than 10k
 -size + file is larger than 1G: 1G
 -size -1G: less than 1G of files

5, depending on the time to find

One day as a unit
             - atime: access time
             - mtime: the modification time
             - ctime: change the time 
in minutes
             - Amin: Access Time
             - Mmin: Modified  
             -cmin: Time change

atime: (access time) shows the time of the last data files do not access, such as system processes directly or indirectly through a number of commands and scripts. (Perform some executable file or script)

mtime: (modify time) shows the contents of the file was modified last time, for example, will be modified when using the vi editor. (Ie Block content)

ctime: (change time) shows the file permissions, owner, group it belongs to, the time change of the number of connections, of course, when the content changes will change (ie inode content changes and Block content changes)

6, permission lookup

+ -perm MODE:
     -perm + 600 : the other is a group owner permissions, as long as there is a match will be successful; objects 600 with three sides, 6 owner using the CentOS7 / 600 
    -perm - 600   : Each object it must have the specified permission, while the establishment of three objects, such as: -003 represent other user must have write and execute permissions

7, after the find to find motion transmission mode

Default: one-time delivery to when looking for specific types of files 
xargs: xargs command that is to let find to find a passing mode to look for a pass to the action, more broken delete files with good 

example: find The -type f | xargs the Command ;

 

Second, find the name of the file to find the basic search command

1, using the name of the current directory to find the file

Find all files named test.c in the current working directory

1 find test.c

2, find the file in your home directory

find /home/  -name  test.c

3, using the name and neglect cases find files

Find the names of all the files for the test and contains both uppercase and lowercase letters in the / home directory

find  /home  -iname   test

 4, using the name lookup directory

find  /  -type  d  -name  test

5, find all PHP files in the directory

find   ./  -name *.php

6, find and delete a single file

find  -type  f  -name   test.php   -exec  rm   -f{}\;

 

Third, find files based on their permissions

1. Find the file permissions to 777

find  ./   -type   f   -perm  777  -print

 

Fourth, based Soso file owner and group

1, to find a single file on the user's

Find an owner for the root file test.c

find   -type    f   -user  root  -name  test.c

2, find all the files in the root group

find  ./  -group root

 

Fifth, find files and directories based on the date and time

1, find the file 50 days before the modified file

find  -mtime  -50  -type  f

2, look for the last 50 days of access to documents

find  -atime  +50  -type  f

3. Find all been modified more than 50 days less than 100 days file

find  -mtime  +50  -100   -type   f

4, modified within the past hour file

find   -mmin  -60  -type   f

5, files that have changed in the last hour

find  -cmin   -60    -type  f

 

Sixth, according to the size of the find files and directories

1. Find the file 50MB

find  ./  -size   50M

2, find the file size of between 50-100

find  /   -size  +50M  -size   -100M

3, 100M find all files and remove them with one command

find   /  -size    100M  -exec   rm   -f   {}\;

4, look for more than 10M of mp3 files, and use a command to delete them

find   /   -type   f   -size   +10M   -name   "*.mp3"  -exec  rm  -f{};

 

Guess you like

Origin www.cnblogs.com/cheneyboon/p/11439453.html