Shell script article 2 (find) 001 # cat command 002cat-n/usr/local/php/lib/php. ini # Add the row number 003cat-s cat.txt # compress multiple empty rows. One empty row 004 005 # find command 006 007 find/home/wangdk-iname "*. txt "-print #-print indicates the name of the matched file. The line break \ n-I ignores the case of 008 009 find. \ (-name "*. txt "-o-name "*. pdf "\) -print #-o: logic or 010 011 #-name: match a file name 012 #-path: match a file path 013 #-regex: match the file path 014 with a regular expression 015 # Regular Expression 016 # find. -regex ". *\(\. sh \) $"017 018 # negation parameter 019 find.! -Name "*. txt "-print020 021 # directory-based deep search 022 # maxdepth maximum search depth 023 # mindepth minimum search depth 024 025 find. -maxdepth 1-type f-print026find. -mindepth 2-type f-print027 028 # type f Common File 029 # type l link symbol 030 # type d directory 031 # type c character device 032 # type B block device 033 # type s socket 034 # type p prop o035 036 037 # search 038 based on file time # access time-atime039 # modification time-mtime040 # Change Time-ctime041 042 #-atime-mtime-ctime Unit days, supported +-greater than, less than 043 044 # print all files accessed in the last 7 days 045 find. -type f-atime-7-print046 047 # print out the 048 find file that has been accessed before 7. type f-atime 7-print049 050 # more than 7 days 051 find. -type f-atime + 7-print052 053 # Time-based search, minute 054 #-amin-mmin-cmin055 056 # file size-based search 057 find. -type f-size + 2 k # files larger than 2 k 058 059 find. -type f-size-2 k # files smaller than 2 k 060 061 # In addition to k, there are other units 062 # B blocks (512 bytes) 063 # c byte 064 # w word 065 # k kilobytes 066 # M MB067 # G GB068 069 # Delete the matching file 070 071 find. -type f-name "*. swp "-delete072 073 # File Permission-based matching 074 find. -type f-perm 644-print075 076 # taking apache as an example, PHP on the web server requires proper execution permissions. We can use the following to search for 077 find. -type f-name "*. php "|-perm 644-print078 079 # find the file 080 Based on the file owner. -type f-user wangdk-print081 082 # execute commands or actions 083 find in combination with find. -type-user root-exec chown wangdk {}\; # In this command, {} is a special string used in combination with the-exec option, replace each matching file with the corresponding file, for example, if the 084 # find Command finds test1.txt and test2.txt whose owner is wangdk, find will execute chown wangk {} and it will be parsed as chown wangdk test1.txt chown wangdk test2.txt085 086 find. -type f-name "*. c "-exec cat {}\;> all_c._files.txt 087 088 #-exec can be followed by any command {} to indicate a match, matching any file name 089 090 find. -type f-mtime + 10-"*. txt "-exec cp {} OLD \; 091 092 # exec cannot execute multiple commands, but can execute shell script-exec. /commands. sh {} \; 093 094 find. -type f-name "*. txt "-exec printf" text file: % s \ n "{}\; 095 #-exec can be combined with printf to generate useful output information 096 097 # let find Skip the specified directory 098 find deve1 // source_path \ (-name ". git "-prune \)-o \ (-type f-print \) 099 # Do not use \ (-type-print \) 20 select the required filter 100 # here, \ (-name ". git-prune \) is used for sorting. the git directory should be excluded, while \ (-type f-print \) only indicates the action to be executed