Three time of the Find command and file under Linux

Source: Internet
Author: User

Tag:command   linux    root directory    

    linux the Find command searches the directory structure for the file and performs the specified action. The Linux Find command provides quite a lot of search criteria and is powerful. Because find has powerful features, it has a lot of options, most of which are worth taking the time to look at. Even if the system contains a network file system ( NFS), the Find command works equally well in the file system, and you only have the appropriate permissions. 1. Command arguments: The directory path that the    pathname: find command looks for. For example, use. To represent the current directory, and/to represent the system root directory. The   -print: find command outputs the matched file to standard output. The    -exec: find command executes the shell command given by the parameter to the matching file. The form of the corresponding command is ' command '  {  } \;, note the space between {   } and \;    -ok:    is the same as-exec, except that the shell command given by this parameter is executed in a more secure mode, before the    executes each command, Will be prompted to let the user determine whether to execute. 2. Command options: -name    find files by file name. -perm    to find files according to file permissions. -prune   Use this option to have the Find command not be found in the currently specified directory, and if you use the-depth option at the same time,-prune will be ignored by the Find command. -user    Search for files according to the owner of the file. -group   finds files according to the group to which the files belong. -mtime -n +n   The file changes time to find the file,  - n indicates that the file change time is now less than n days, + n indicates that the file change time is now N days ago. The Find command also has the-atime and-ctime  options, but both of them and the-m time option. -nogroup   finds a file that does not have a valid owning group, that is, the group to which the file belongs in/etc/groupsDoes not exist in the. -nouser   finds a file without a valid owner, that is, the owner of the file does not exist in the/etc/passwd. -newer file1 ! file2   look for a file that changes time than the file File1 new but older than the file file2. -type   finds a file of a certain type, such as a:b -  block device file. d -  directory. c -  character device files. p -  pipeline file. l -  the symbolic link file. f -  ordinary files. -size n:[c]  finds files with a file length of n blocks, with C indicating the length of the file in bytes. -depth: When looking for a file, first find the file in the current directory, and then look in its subdirectories. -fstype: Find files located in a file system of a certain type, these file system types can usually be found in the configuration file/etc/fstab, which contains information about the file system in this system. -mount: Does not cross the file system mount point when locating files. -follow: If the find command encounters a symbolic link file, it tracks to the file that the link points to. -cpio: Use the cpio command for matching files to back up these files to the tape device. In addition, the following three differences: -amin n    find the last n minutes of access to a file in the system-atime n   find the last n*24 hour Access file in the system-cmin  n    find files in the last n minutes of the system changed file status-ctime n   find the last n*24 hours in the System file status changed file-mmin n     find the last n minutes in the system file data changed file-mtime n   find the last n*24 hours in the system file data is changed #-print  Outputs the found file to the standard output #-exec    command    {} \;        -----will find out.File Execution command operation,{}  and  \; have spaces between #-ok  and-exec, except to consult the user before the Operation  ====================================== ============== -name    filename                 #查找名为filename的文件-perm                          # To find-user     username          by execute permission       #按文件属主来查找-group groupname                #按组来查找-mtime    -n +n                   #按文件更改时间来查找文件,-n means less than n days, + n refers to n days before-atime     -n +n                  #按文Access time to check gin: 0px ">-perm                            #按执行权限来查找-user      username              # Find-group groupname              by file owner   #按组来查找-mtime    -n +n                   #按文件更改时间来查找文件,-n refers to +n or less than n days ago-atime      -n +n                  #按文件访问时间来查找文件,-n refers to +n or less than n days ago  -ctime     -n +n                  #按文件创建时间来查找文件,-n refers to +n or less than n days ago  -nogroup                      # No valid group of documents, that is, the genus of the file does not exist in the/etc/groups-nouser                         #查无有效属主的文件, that is, the owner of the document does not exist in the/etc/passwd-newer     f1 !f2                  find files,-n refers to the nth days, +n refers to n days ago  -ctime     -n +n                  #按文件创建时间来查找文件,-n means less than n days, + n refers to n days ago  -nogroup                        #查无有效属组的文件, that is, the genus of the file does not exist in/etc/groups-nouser                          #查无有效属主的文件, which is the owner of the document in/etc/pasThe SWD does not save-newer    f1 !f2                  #查更改时间比f1新但比f2旧的文件-type      b/d/c/p/l/f            #查是块设备, directories, character devices, pipelines, symbolic links, common file-size        n[c]                  #查长度为n块 [or N bytes] of file-depth                          #使查找在进入子目录前先行查找完本目录-fstype                          #查更改时间比f1新但比f2旧的文件-mount                          #查文件时不跨越文件系统mount点-follow                        # If you encounter a symbolic link file, follow the file that the link refers to-cpio                           #对匹配的文件使用cpio命令, back them up to tape devices-prune                           #忽略某个目录   3.linux The use of the Find command  1.  basic usage:      1.find / -name  file name          find ver1.d  ver2.d -name  ' *.c '  -print     find ver1.d,ver2.d *.c file and print        2.find . -type d -print    Search from the current directory, find only the directory, Prints the path name. Can be used to print the directory structure.      2.  no error finding:      find / -name  Access_log 2 >/dev/null      3.  Find:       by size find / -size 1500c  (finds a 1,500-byte file, c represents bytes)       find /  -size +1500c  (find files larger than 1,500 bytes, + = greater than)            find / -size +1500c  (find files less than 1,500 bytes in size-Indicates less than)            4.  by Time:      find / -amin n  Last n minutes        find / -atime n  last n days        find / -cmin n  Last n minutes Change status       find /  -ctime n  Last n days Change status       5.  other:       find / -empty  blank files, blank folders, and folders without subdirectories       find / - false  always wrong files in the Find system       find / -fstype type  find files that exist in the specified file system, such as type ext2       find / -gid n  Group ID n File       find  / -group gname  Group named Gname file       find / -depth  n  first find file contents in a certain level of the specified directory       find / -maxdepth levels  Find 6.  logic       -and  conditions and  -or  conditions or 7.  lookup strings in a hierarchical directory in descending order       find . -name  ' *.html '  -exec grep  ' mailto: ' {}   Two. Under Windows, a file has: creation time, modification time, access time. And under Linux, a file also has three kinds of time, namely: Access time, modification time, state change time. Mtime: File Last Modified time CTime: File recent properties and permissions modified time Atime: The time the file was recently accessed  1.ls -l filename (LS default is mtime)     -rw-rw-r-- 1 lawrance lawrance 27 Oct  5 02:09  Filename 2.ls -l --time=ctime filename &nbsP; -rwxr-xr-x 1 lawrance lawrance 27 oct  6 02:50 filename  3.ls -l --time=atime filename   -rw-rw-r-- 1 lawrance  Lawrance 27 oct  6 02:30 filename In addition, you can format the output file for three different times, such as: 1.find . -name  file -printf  "%ay-%am-%ad %ah:%am:%as" 2.find . -name file -printf   "%ty-%tm-%td %th:%tm:%ts" 3.find . -name file -printf  "%CY-%Cm-%Cd %CH :%cm:%cs "


This article is from the "0-point Time" blog, please make sure to keep this source http://10741764.blog.51cto.com/10731764/1773811

Three time of the Find command and file under Linux

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.