Linux Find command Lookup file parameter description

Source: Internet
Author: User
Tags current time file permissions


1, the general form of Find command;

Find Pathname-options [-print-exec-ok ...]


1. Find

Find is the most common and powerful search command you can use to find any file you're looking for.

Find uses the following format:

$ find < Specify directory > < specify conditions > < specify action >

-< Specify directory: the directory to search for and all of its subdirectories. The current directory is assumed by default.

-< Specify conditions: The characteristics of the file to search for.

-< Specify action: Perform specific processing of search results.

If nothing is added, find defaults to search the current directory and its subdirectories, and does not filter any results (that is, all files are returned) and displays them all on the screen.

Use example of Find:

$ find. -name ' my* '

Searches the current directory (with subdirectories, below) for all file names starting with my.

$ find. -name ' my* '-ls

Searches the current directory for all files whose filenames start with my, and displays their details.

$ find. -type f-mmin-10

Searches the current directory for all normal files that have been updated in the last 10 minutes. If you do not add the-type f parameter, search for normal files + special files + directories.


The directory path found by the Find command. For example, to represent the current directory, with/to represent the system root directory.
The-print:find command outputs matching files to the standard output.
The-exec:find command executes the shell command given by the parameter to the matching file. The corresponding command is in the form of ' command ' {};, note the space between {} and;
-ok: The same as the-exec, but in a more secure mode to execute the shell command given by this parameter, before executing each command, will be prompted to let the user determine whether to execute.

The Find command has several options for searching for files based on your system's timestamp. These time stamps include

Mtime file content Last modified time
Atime the time the file was read or accessed
CTime file state Change time

The meaning of Mtime and atime is easy to understand, and ctime needs more explanations. Because the inode maintains the metadata on each file, the Inode data will also change if the metadata associated with the file changes. This could be caused by a series of actions, including creating symbolic links to files, changing file permissions, or moving files. Because the contents of the file are not read or modified in these cases, mtime and atime will not change, but CTime will change.

These time options need to be used in conjunction with a value of n, specified as-n, N, or +n.

N * 24
+1 means 1 * 24 + 24 hours away.
+0 means 0 * 24 + 24 hours away
1 means 1 * 24 + 24 to 24.
0 means 0 * 24 + 24 to 0.
-1 for 0 * 24 +24, even for future time ...

1. Current time 24 hours-current time (Yesterday-today)
#find. -mtime 0
2. Current time 48 hours ago – Current time 24 hours ago (day before yesterday)
#find. -mtime 1
3. Current time 48 hours ago (2 days ago)
#find. -mtime +1
4. Current time 24 hours – current time (yesterday-today)
#find. -mtime-1

Parameter and description

 
 
  1. -name filename #查找名为filename的文件
  2. -perm #按执行权限来查找
  3. -user username #按文件属主来查找
  4. -group GroupName #按组来查找
  5. -mtime-n +n #按文件更改时间来查找文件,-n refers to n days, +n refers to n days ago
  6. -atime-n +n #按文件访问时间来查GIN: 0px ">
  7. -ctime-n +n #按文件创建时间来查找文件,-n refers to n days, +n refers to n days ago
  8. -nogroup #查无有效属组的文件, that is, the group of files does not exist in/etc/groups
  9. -nouser #查无有效属主的文件, that the owner of the document does not exist in the/etc/passwd
  10. -newer F1!f2 Find files,-n refers to the nth days, +n refers to n days ago
  11. -ctime-n +n #按文件创建时间来查找文件,-n refers to n days, +n refers to n days ago
  12. -nogroup #查无有效属组的文件, that is, the group of files does not exist in/etc/groups
  13. -nouser #查无有效属主的文件, that the owner of the document does not exist in the/etc/passwd
  14. -newer F1!F2 #查更改时间比f1新但比f2旧的文件
  15. -type b/d/c/p/l/f #查是块设备, directories, character devices, pipelines, symbolic links, normal files
  16. -size N[c] #查长度为n块 [or N-byte] files
  17. -depth #使查找在进入子目录前先行查找完本目录
  18. -fstype #查更改时间比f1新但比f2旧的文件
  19. -type b/d/c/p/l/f #查是块设备, directories, character devices, pipelines, symbolic links, normal files
  20. -size N[c] #查长度为n块 [or N-byte] files
  21. -depth #使查找在进入子目录前先行查找完本目录
  22. -fstype #查位于某一类型文件系统中的文件, these file system types can usually be found in/etc/fstab
  23. -mount #查文件时不跨越文件系统mount点
  24. -follow #如果遇到符号链接文件, track the file that the link refers to
  25. -cpio%; #查位于某一类型文件系统中的文件, these file system types can usually be found in/etc/fstab
  26. -mount #查文件时不跨越文件系统mount点
  27. -follow #如果遇到符号链接文件, track the file that the link refers to
  28. -cpio #对匹配的文件使用cpio命令, back them up to tape devices
  29. -prune #忽略某个目录

Example:

 
 
  1. Find-name april* Find files starting with April in the current directory
  2. Find-name april* Fprint file finds files starting with April in the current directory, and outputs the results into file
  3. Find-name ap*-o-name may* Find files that start with AP or May
  4. Find/mnt-name Tom.txt-ftype vfat Find files under/mnt with name tom.txt and file system type VFAT
  5. Find/mnt-name T.txt! -ftype vfat find files under/mnt with name tom.txt and file system type not VFAT
  6. Find/tmp-name wa*-type L in/tmp looks for a file named WA with a type of symbolic link
  7. Find/home-mtime-2, check the files that were changed in the last two days under/home.
  8. Find/home-atime-1 check for files accessed within 1 days.
  9. Find/home-mmin +60, check the files that were changed 60 minutes ago in/home.
  10. Find/home-amin +30, check for files accessed last 30 minutes ago.
  11. Find/home-newer tmp.txt a file or directory that is newer than tmp.txt in/home
  12. Find/home-anewer tmp.txt a file or directory near/home for access time than Tmp.txt
  13. Find/home-used-2 lists files or directories that have been accessed within 2nd after a file or directory has been altered
  14. Find/home-user CNSCN lists files or directories within the/home directory that belong to the user Cnscn
  15. Find/home-uid +501 lists files or directories within the/home directory that have a user ID greater than 501
  16. Find/home-group CNSCN lists files or directories within the/home group as CNSCN
  17. Find/home-gid 501 lists files or directories in/home with a group ID of 501
  18. Find/home-nouser lists files or directories within/home that are not part of the local user
  19. Find/home-nogroup lists files or directories within/home that are not part of the local group
  20. Find/home-name tmp.txt-maxdepth 4 lists Tmp.txt in/home with a maximum depth of 3 layers
  21. Find/home-name tmp.txt-mindepth 3, starting on the 2nd floor.
  22. Find/home-empty find files or empty directories of size 0
  23. Find/home-size +512k check for files larger than 512k
  24. find/home-size-512k check for files less than 512k
  25. Find/home-links +2 Check for files or directories with a hard connection number greater than 2
  26. Find/home-perm 0700 Search for files or directories with permission of 700
  27. Find/tmp-name tmp.txt-exec Cat {};
  28. Find/tmp-name Tmp.txt-ok rm {};
  29. Find/-amin-10 # finds files accessed in the last 10 minutes of the system
  30. Find/-atime-2 # finds files accessed in the last 48 hours of the system
  31. Find/-empty # Look for files or folders that are empty in the system
  32. Find/-group Cat # finds files that belong to Groupcat in the system
  33. Find/-mmin-5 # finds files that have been modified in the last 5 minutes of the system
  34. Find/-mtime-1 #查找在系统中最后24小时里修改过的文件
  35. Find/-nouser #查找在系统中属于作废用户的文件
  36. Find/-user Fred #查找在系统中属于FRED这个用户的文件

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.