find 명령어 (AIX 5.3·6.1)

핵심 정리

  • 지정한 경로마다 디렉터리 트리를 재귀적으로 내려가며, 불(Boolean) 식에 맞는 파일을 찾습니다. 식이 없으면 -print로 경로를 출력합니다.
  • 자주 쓰는 식: -name(이름 패턴), -type(종류), -size(512바이트 블록, c를 붙이면 바이트), -mtime·-atime·-ctime(일), -mmin·-amin·-cmin(분), -perm, -user, -group, -newer.
  • 숫자 n은 +n(n보다 큼), -n(n보다 작음), n(정확히 n)으로 씁니다.
  • -exec 명령 {} \;로 찾은 파일마다 명령을 실행하고, -ok는 실행 전에 묻습니다. {} +로 끝내면 여러 파일을 한 번에 넘깁니다.
  • 식은 \( \)(묶음), !(NOT), -a(AND, 생략 가능), -o(OR) 순서로 결합합니다. -prune은 디렉터리 아래로 내려가지 않고, -xdev는 다른 파일 시스템으로 넘어가지 않습니다.
  • AIX에만 있는 것: -ea(ACL·EA가 있는 파일), -long(-ls에서 긴 사용자 이름), -cpio(cpio 형식으로 장치에 쓰기).
항목 내용
버전 AIX 5.3, AIX 6.1 (내용 거의 같음, 6.1에서 -fstype 형식 목록이 늘어남)
원문 IBM Commands Reference — 5.3 Volume 2, 6.1 Volume 2
파일 /usr/bin/find, /bin/find(링크)
관련 명령어 ln, chmod, cpio, xargs

목적

식에 맞는 파일을 찾습니다.

영어 원문

Finds files with a matching expression.

구문

text
find [ -H | -L ] Path ... [ Expression ]

설명

find 명령은 지정한 Path 매개변수마다 디렉터리 트리를 재귀적으로 찾아 내려가며, 불(Boolean) 식에 맞는 파일을 찾습니다. 불 식은 아래에서 설명하는 항(term)으로 씁니다. 디렉터리 구조를 재귀적으로 내려갈 때, 현재 계층에 심볼릭 링크로 연결된 디렉터리 안으로는 내려가지 않습니다. 출력은 Expression 매개변수로 지정한 항에 따라 달라집니다.

find 명령은 4.3 BSD의 빠른 찾기(fast-find) 구문을 지원하지 않습니다.

영어 원문

The find command recursively searches the directory tree for each specified Path parameter, seeking files that match a Boolean expression. The Boolean expression is written by using the terms that are provided in the following text. When the find command is recursively descending directory structures, it does not descend into directories that are symbolically linked into the current hierarchy. The output from the find command depends on the terms that are specified by the Expression parameter.

The find command does not support the 4.3 BSD fast-find syntax.

플래그

플래그 설명
-H 명령줄에서 만난 심볼릭 링크마다, 평가할 파일 정보와 파일 종류를 링크 자체가 아닌 링크가 가리키는 파일의 것으로 합니다. 가리키는 파일이 없으면 링크 자체의 정보를 씁니다. 명령줄에 없는 심볼릭 링크는 모두 링크 자체의 정보를 씁니다.
-L 모든 심볼릭 링크에 대해, 평가할 파일 정보와 파일 종류를 링크 자체가 아닌 링크가 가리키는 파일의 것으로 합니다.
영어 원문
  • -H — Causes the file information and file type that are evaluated for each symbolic link that is encountered on the command line to be those of the file that is referenced by the link, and not the link itself. If the referenced file does not exist, the file information and type are for the link itself. File information for all symbolic links not on the command line is that of the link itself.
  • -L — Causes the file information and file type that are evaluated for each symbolic link to be those of the file that is referenced by the link, and not the link itself.

식(Expression)

다음 불 식과 변수는 Path와 Expression 매개변수로 정한 find 명령의 검색 범위를 설명합니다.

참고: 아래 정의에서 n 변수는 10진 정수로, +n(n보다 큼), -n(n보다 작음), n(정확히 n)으로 쓸 수 있습니다. Number 변수는 10진 정수로, +Number(Number보다 큼), -Number(Number보다 작음), Number(Number-1부터 Number까지)로 쓸 수 있습니다.

시간 조건

-amin, -atime, -cmin, -ctime, -mmin, -mtime은 모두 같은 방식으로 계산합니다. find를 시작한 시각(초기화 시각)에서 파일의 시각을 빼고, 단위(60초 또는 86,400초 = 24시간)로 나눈 값(나머지는 버림)을 n과 비교합니다.

식 비교하는 시각 단위
-amin n 마지막 접근 시각 60초(분)
-atime n 마지막 접근 시각 86,400초(일)
-cmin n i-node 변경 시각 60초(분)
-ctime n i-node 변경 시각 86,400초(일)
-mmin n 마지막 수정 시각 60초(분)
-mtime n 마지막 수정 시각 86,400초(일)
n의 형태 참이 되는 경우
n 계산한 값이 n입니다.
-n 계산한 값이 n보다 작습니다.
+n 계산한 값이 n보다 큽니다(UNIX03 동작이면 n+1보다 큼).
  • 예를 들어 -amin 2는 파일에 1~2분 안에 접근했으면 참입니다.
  • find를 시작한 뒤에 접근·변경·수정된 파일은 따지지 않습니다. 다만 UNIX03이 아닌 동작에서 단항 NOT 연산자 안에 쓰면, 시작한 뒤에 바뀐 파일도 n 값까지 표시합니다.
  • -atime, -ctime, -mtime의 정의는 Single UNIX Specification 버전 3(UNIX03)에 맞게 바뀌었습니다. 예전 동작은 "n-1에서 n 사이의 24시간 배수 안에 접근(수정)했으면 참"이었습니다. 기본은 UNIX03 이전 동작입니다. UNIX03 동작을 쓰려면 환경 변수 XPG_SUS_ENV를 ON, XPG_UNIX98을 OFF로 정합니다. 예전 동작은 XPG_UNIX98을 ON으로 정하면 됩니다.

이름·종류·크기·소유자

식 참이 되는 경우
-name File File 변수의 값이 파일 이름과 맞습니다. 셸의 파일 이름 생성 문자(sh 명령 참고)를 쓸 수 있습니다. 패턴은 따옴표로 감싸거나 이스케이프 문자로 막아야 합니다. 셸에서 find를 쓸 때 이스케이프 문자를 쓰며, 패턴 안의 이스케이프 문자는 백슬래시(\)입니다. 와일드카드(패턴 일치) 문자는 따옴표 안에 있을 때 쓸 수 있습니다. [a-z] 같은 식에서 하이픈은 현재 대조 순서에 따른 범위를 뜻합니다.
-type Type 파일 종류가 Type과 같습니다. b(블록 특수 파일), c(문자 특수 파일), d(디렉터리), f(일반 파일), l(심볼릭 링크), p(FIFO, 이름 있는 파이프), s(소켓).
-size n 파일 길이가 n블록(블록당 512바이트)입니다. 비교할 때 파일 크기를 가장 가까운 블록으로 올림합니다.
-size nc 파일 길이가 정확히 n바이트입니다. n 뒤의 c는 블록이 아니라 바이트 단위로 잰다는 뜻입니다.
-user User 파일이 지정한 사용자의 것입니다. User 값이 숫자이고 /etc/passwd에 로그인 이름으로 없으면 사용자 ID로 해석합니다.
-group Group 파일이 지정한 그룹의 것입니다. Group 값이 숫자이고 /etc/group에 없으면 그룹 ID로 해석합니다.
-nouser 파일의 사용자가 /etc/passwd 데이터베이스에 없습니다.
-nogroup 파일의 그룹이 /etc/group 데이터베이스에 없습니다.
-inum n 파일의 i-node 번호가 n입니다.
-links n 파일의 링크 수가 n입니다. 링크는 ln 명령을 참고합니다.
-newer File 현재 파일이 File 변수가 가리키는 파일보다 최근에 수정됐습니다.
-fstype Type 파일이 속한 파일 시스템의 형식이 Type입니다. jfs(저널 파일 시스템), nfs(네트워크 파일 시스템), jfs2(향상된 저널 파일 시스템), procfs(proc 파일 시스템), namefs(name 파일 시스템). 5.3 문서에는 jfs와 nfs만 있습니다.
-ea 파일에 접근 제어 정보(ACL)나 확장 속성(EA)이 있습니다.

권한

식 참이 되는 경우
-perm [-]OctalNumber 파일의 권한 코드가 OctalNumber와 정확히 같습니다. 앞에 -(하이픈)를 붙이면 적어도 이 권한이 모두 켜져 있으면 참입니다. OctalNumber는 8진수 9자리까지 쓸 수 있습니다. 권한은 chmod 명령을 참고합니다.
-perm [-]Mode Mode는 chmod의 기호 모드와 같은 형식입니다(아래 설명). 하이픈이 없으면 권한 비트가 결과 템플릿과 정확히 같을 때, 하이픈이 있으면 템플릿의 비트가 적어도 모두 켜져 있을 때 참입니다.

-perm 기호 모드의 해석: 처음에는 모든 파일 모드 비트가 꺼진 템플릿을 가정하고, 연산 기호를 다음과 같이 적용합니다.

  • +: 템플릿에 해당 모드 비트를 켭니다.
  • -: 해당 비트를 끕니다.
  • =: 프로세스의 파일 생성 마스크와 상관없이 해당 모드 비트를 켭니다.

연산 기호 -는 Mode의 첫 글자로 쓸 수 없습니다. 앞에 붙는 선택 하이픈과 헷갈리지 않게 하기 위해서입니다. 처음 모드가 모두 꺼져 있으므로 -로 시작해야 하는 기호 모드는 없습니다.

참고(TCB): TCB 환경에 속한 파일은 권한에 보안 비트가 더해집니다. 이런 파일은 S_ITCB 비트가 켜져 있으며, 이 보안 비트는 0x010000000으로 정의됩니다. 그래서 TCB 파일의 8진수 권한 값에는 다른 권한 비트와 함께 100000000 비트를 넣어야 합니다. 예를 들어 find -perm 100000600 -print는 소유자 읽기·쓰기 권한만 있고 TCB 환경에 속한 파일의 이름을 나열합니다.

동작

식 설명
-print 늘 참입니다. 현재 경로 이름을 표시합니다. -exec, -ls, -ok가 없으면 find는 -print가 있다고 가정합니다.
-ls 늘 참입니다. 현재 경로 이름과 통계(i-node 번호, KB(1024바이트) 단위 크기, 보호 모드, 하드 링크 수, 사용자, 그룹, 바이트 단위 크기, 수정 시각)를 함께 출력합니다. 특수 파일이면 크기 자리에 주·부 장치 번호를, 심볼릭 링크면 가리키는 파일의 경로를 -> 뒤에 출력합니다. 형식은 ls -filds와 비슷하지만 ls 명령을 실행하지 않고 내부에서 만들므로, 보호 모드 등에서 ls 출력과 다를 수 있습니다.
-long -ls와 함께 쓰면 사용자·그룹 이름을 앞 8글자로 자르지 않고 모두 출력합니다.
-exec Command 지정한 명령을 실행해 종료 상태 0을 돌려주면 참입니다. 명령의 끝은 따옴표로 감싼 세미콜론, 이스케이프한 세미콜론, 또는 더하기 기호로 표시해야 합니다. {}(중괄호) 두 글자가 든 인수 뒤에는 명령의 끝을 나타내는 더하기 기호가 와야 합니다. 명령 매개변수 {}는 현재 경로 이름으로 바뀝니다.
-ok Command -exec와 같지만, 명령을 시작할지 먼저 확인합니다. 긍정하면 명령을 시작합니다. 명령의 끝은 따옴표로 감싼 세미콜론이나 \;(백슬래시로 이스케이프한 세미콜론)로 표시해야 합니다.
-cpio Device 현재 파일을 cpio 명령 형식으로 지정한 장치에 씁니다.
-depth 늘 참입니다. 디렉터리 자체보다 그 안의 항목을 먼저 처리하도록 내려갑니다. 쓰기 권한이 없는 디렉터리 안의 파일을 cpio로 옮길 때 좋습니다.
-prune 늘 참입니다. 현재 경로가 디렉터리면 그 아래로 내려가지 않습니다. -depth를 지정하면 -prune은 무시합니다.
-xdev 늘 참입니다. Path로 지정한 파일 시스템과 다른 파일 시스템으로 넘어가지 않습니다.
-follow 심볼릭 링크와 하드 링크를 따라갑니다.
\( Expression \) 괄호 안의 식이 참이면 참입니다.

연산자

식은 다음 연산자로 결합하며, 위에 있을수록 먼저 계산합니다.

  1. ( Expression ): 식과 연산자를 괄호로 묶습니다. 괄호는 셸에서 특별한 뜻이 있어 백슬래시로 이스케이프해야 합니다.
  2. ! Expression: 식을 부정합니다(!는 단항 NOT 연산자).
  3. Expression [ -a ] Expression: 식을 잇습니다. 두 항을 나란히 쓰면 AND이고, -a로 명시할 수도 있습니다.
  4. Expression -o Expression: OR 연산자입니다. 첫 식이 참이면 둘째 식은 계산하지 않습니다.

참고:

  • find와 cpio를 함께 쓸 때는 -follow 옵션과 cpio의 -L 옵션을 함께 써야 합니다. 둘을 함께 쓰지 않으면 원하지 않는 결과가 납니다.
  • 식이 없으면 -print를 씁니다. 지정한 식에 -exec, -ok, -print 중 아무것도 없으면 식을 (지정한 식) -print로 바꿉니다.
  • -user, -group, -newer는 인수를 한 번만 평가합니다.
  • -exec나 -ok로 실행한 명령은 같은 파일에 대한 뒤의 항에 영향을 주지 않습니다.
영어 원문

These Boolean expressions and variables describe the search boundaries of the find command as defined in the Path and Expression parameters.

Note: In the following definitions, the n variable specifies a decimal integer that can be expressed as +n (more than n), -n (less than n), or n (exactly n) and the Number variable specifies a decimal integer that can be expressed as +Number (more than Number), -Number (less than Number), or Number (Number-1 to Number).

  • \(Expression\) — Evaluates to the value True if the expression in parentheses is true.
  • -amin n — The value of n can be one of the following values: n Evaluates as True if the file access time subtracted from the initialization time, divided by 60 seconds (with any remainder discarded), is n. -n Evaluates as True if the file access time subtracted from the initialization time, divided by 60 seconds (with any remainder discarded), is less than n. +n Evaluates as True if the file access time subtracted from the initialization time, divided by 60 seconds (with any remainder discarded), is greater than n (in case of UNIX03, greater than n+1). For example, -amin 2 is true if the file is accessed within 1 to 2 minutes. Note: Files that are accessed after the find command start time are not taken into account. However, when the find command is used within the unary NOT operator for non-UNIX03 behavior, the files that are modified after the command start time are displayed until the value of n.
  • -atime n — The value of n can be one of the following values: n Evaluates as True if the file access time subtracted from the initialization time, divided by 86400 seconds (with any remainder discarded), is n. -n Evaluates as True if the file access time subtracted from the initialization time, divided by 86400 seconds (with any remainder discarded), is less than n. +n Evaluates as True if the file access time subtracted from the initialization time, divided by 86400 seconds (with any remainder discarded), is greater than n (in case of UNIX03, greater than n+1). Note: The definition of -atime is changed to comply with the Single UNIX Specification, Version 3. The previous behavior of -atime evaluated as True if the file was accessed in n-1 to n multiples of 24 hours. By default, find -atime works like it did before UNIX03. The UNIX03 behavior can be obtained by setting the environment variables XPG_SUS_ENV to ON and XPG_UNIX98 to OFF. The previous behavior for this option can be obtained by setting the XPG_UNIX98 variable to ON. Files that are accessed after the find command start time is not taken into account. However, when the find command is used within the unary NOT operator for non-UNIX03 behavior, the files that are modified after the command start time are displayed until the value of n.
  • -cmin n — The value of n can be one of the following values: n Evaluates as True if the file i-node modification time subtracted from the initialization time, divided by 60 seconds (with any remainder discarded), is n. -n Evaluates as True if the file i-node modification time subtracted from the initialization time, divided by 60 seconds (with any remainder discarded), is less than n. +n Evaluates as True if the file i-node modification time subtracted from the initialization time, divided by 60 seconds (with any remainder discarded), is greater than n (in case of UNIX03, greater than n+1). Note: Files with i-nodes that are modified after the find command start time are not taken into account. However, when the find command is used within the unary NOT operator for non-UNIX03 behavior, files with i-nodes modified after the command start time are displayed until the value of n.
  • -cpio Device — Writes the current file to the specified device in the cpio command format.
  • -ctime n — The value of n can be one of the following values: n Evaluates as True if the file i-node modification time subtracted from the initialization time, divided by 86400 seconds (with any remainder discarded), is n. -n Evaluates as True if the file i-node modification time subtracted from the initialization time, divided by 86400 seconds (with any remainder discarded), is less than n. +n Evaluates as True if the file i-node modification time subtracted from the initialization time, divided by 86400 seconds (with any remainder discarded), is greater than n (in case of UNIX03, greater than n+1). Note: The definition of -ctime is changed to comply with the Single UNIX Specification, Version 3. The previous behavior of -ctime evaluated as True if the file was accessed in n-1 to n multiples of 24 hours. By default, find -ctime works like it did before UNIX03. The UNIX03 behavior can be obtained by setting the environment variables XPG_SUS_ENV to ON and XPG_UNIX98 to OFF. The previous behavior for this option can be obtained by setting the XPG_UNIX98 variable to ON. Files with i-nodes modified after the find command start time is not taken into account. However, when the find command is used within the unary NOT operator for non-UNIX03 behavior, files with i-nodes modified after the command start time is displayed until the value of n.
  • -depth — Always evaluates to the value True. Causes the descent of the directory hierarchy to be done so that all entries in a directory are affected before the directory itself is affected. It can be useful when the find command is used with the cpio command to transfer files that are contained in directories without write permission.
  • -ea — Evaluates to the value True if file has either access control information (ACL) or Extended attributes (EA) set.
  • -exec Command — Evaluates to the value True if the specified command runs and returns a 0 value as exit status. The end of the specified command must be punctuated by a semicolon in quotation marks, an escaped semicolon, or a plus sign. An argument that contains the two characters {} (braces) must be followed by a plus sign that punctuates the end of the specified command. A command parameter {} (braces) is replaced by the current path name.
  • -follow — Causes symbolic and hard links to be followed.
  • -fstype Type — Evaluates to the value True if the file system to which the file belongs is of the specified type. The Type variable has a value of jfs (journaled file system), nfs (network file system), jfs2 (enhanced journaled file system), procfs (proc file system), or namefs (name file system).
  • -group Group — Evaluates to the value True if the file belongs to the specified group. If the value of the Group variable is numeric and does not appear in the /etc/group file, it is interpreted as a group ID.
  • -inum n — Evaluates to the value True if file has an i-node matching the value of the n variable.
  • -links n — Evaluates to the value True if the file has the specified number of links. See the ln command for a description of links.
  • -long — Prints all available characters of each user/group name instead of truncating to the first 8 when used in combination with -ls.
  • -ls — Always evaluates to the value True. Causes the current path name to be printed together with its associated statistics. These statistics include the following values: • I-node number • Size in KB (1024 bytes) • Protection mode • Number of hard links • User • Group • Size in bytes • Modification time If the file is a special file, the size field contains the major and minor device numbers. If the file is a symbolic link, the path name of the linked-to file is printed preceded by the -> (hyphen, greater than) symbols. Formatting is similar to that of the ls -filds command, however formatting is done internally without running the ls command. Therefore, differences in output with the ls command might exist, such as with the protection mode.
  • -mmin n — The value of n can be one of the following values: n Evaluates as True if the file modification time subtracted from the initialization time, divided by 60 seconds (with any remainder discarded), is n. -n Evaluates as True if the file modification time subtracted from the initialization time, divided by 60 seconds (with any remainder discarded), is less than n. +n Evaluates as True if the file modification time subtracted from the initialization time, divided by 60 seconds (with any remainder discarded), is greater than n (in case of UNIX03, greater than n+1). Note: Files that are modified after the find command start time are not taken into account. However, when the find command is used within the unary NOT operator for non-UNIX03 behavior, the files that are modified after the command start time are displayed until the value of n.
  • -mtime n — The value of n can be one of the following values: n Evaluates as True if the file modification time subtracted from the initialization time, divided by 86400 seconds (with any remainder discarded), is n. 86400 seconds is 24 hours. -n Evaluates as True if the file modification time subtracted from the initialization time, divided by 86400 seconds (with any remainder discarded), is less than n. +n Evaluates as True if the file modification time subtracted from the initialization time, divided by 86400 seconds (with any remainder discarded), is greater than n (in case of UNIX03, greater than n+1). Note: The definition of -mtime is changed to comply with the Single UNIX Specification, Version 3. The previous behavior of -mtime evaluated as True if the file is modified in n-1 to n multiples of 24 hours. By default, find -mtime works like it did before UNIX03. The UNIX03 behavior can be obtained by setting the environment variables XPG_SUS_ENV to ON and XPG_UNIX98 to OFF. The previous behavior for this option can be obtained by setting the XPG_UNIX98 variable to ON. Files that are modified after the find command start time are not taken into account. However, when the find command is used within the unary NOT operator for non-UNIX03 behavior, the files modified after the command start time are displayed until the value of n.
  • -name File — Evaluates to the value True if the value of the File variable matches the file name. The typical shell file name generation characters (see the sh command) can be used. The pattern must be enclosed in either quotation marks or the escape characters. The escape character is used when the find command is used from the shell. A backslash (\) is used as an escape character within the pattern. You can use wildcard (pattern-matching) characters, provided they are in quotation marks. For more information about using wildcard characters, see Pattern matching with wildcards and metacharacters in Operating system and device management. In an expression such as [a-z], the hyphen means through according to the current collating sequence. A collating sequence might define equivalence classes for use in character ranges. For more information about collating sequences and equivalence classes, see “National Language Support Overview” in the National Language Support Guide and Reference.
  • -newer File — Evaluates to the value True if the current file is modified more recently than the file indicated by the File variable.
  • -nogroup — Evaluates to the value True if the file belongs to a group not in the /etc/group database.
  • -nouser — Evaluates to the value True if the file belongs to a user not in the /etc/passwd database.
  • -ok Command — The same as the -exec expression, except that the find command verifies whether it must start the specified command. An affirmative response starts the command. The end of the specified command must be punctuated by a semicolon that is enclosed in quotation marks or the \; (backslash-escape semicolon).
  • -perm [-] OctalNumber — Evaluates to the value True if the permission code of the file exactly matches the OctalNumber parameter. For details about file permissions, refer to the chmod command. If the optional - (hyphen) is present, this expression evaluates to the value true if at least these permissions are set. The OctalNumber parameter can be up to 9 octal digits. Note: For files that are a part of TCB environment, additional security bits are added to the permission of the files. These files have the S_ITCB bit set and the security bit set is defined as 0x010000000. Therefore, the octal permissions value of a TCB enabled file must include the bit setting of 100000000 along with its other permission bits. Example: To list a file, which is a part of the TCB environment, find -perm 100000600 -print. It lists the names of the files that have only owner-read and owner-write permission and are a part of the TCB environment. See the chmod command for an explanation of permission codes.
  • -perm [-] Mode — The mode argument is used to represent file mode bits. It is identical in format to the <symbolicmode> operand described in chmod, and is interpreted as follows: Initially, a template is assumed with all file mode bits cleared. Op (-) symbols have the following function: + Sets the appropriate mode bits in the template - Clears the appropriate bits = Sets the appropriate mode bits, without regard to the contents of the process' file mode creation mask The op symbol - cannot be the first character of mode. It avoids ambiguity with the optional leading hyphen. Because the initial mode is all bits off, there are no symbolic modes that must use - as the first character. If the hyphen is omitted, the primary evaluates as True when the file permission bits exactly match the value of the resulting template. Otherwise, if mode is prefixed by a hyphen, the primary evaluates as True if at least all bits in the resulting template are set in the file permission bits. The Mode parameter is identical to the chmod command syntax. This expression evaluates to the value True if the file has exactly these permissions. If the optional - (hyphen) is present, this expression evaluates to the value True if at least these permissions are set.
  • -print — Always evaluates to the value True. Displays the current path name. The find command assumes a -print expression, unless the -exec, - ls, or -ok expressions are present.
  • -prune — Always evaluates to the value True. Stops the descent of the current path name if it is a directory. If the -depth flag is specified, the -prune flag is ignored.
  • -size n — Evaluates to the value True if the file is the specified n of blocks long (512 bytes per block). The file size is rounded up to the nearest block for comparison.
  • -size nc — Evaluates to the value True if the file is exactly the specified n of bytes long. Adding c to the end of the n variable indicates that the size of the file is measured in individual bytes not blocks.
  • -type Type — Evaluates to the value True if the Type variable specifies one of the following values: b Block special file c Character special file d Directory f Plain file l Symbolic link p FIFO (a named pipe) s Socket
  • -user User — Evaluates to the value True if the file belongs to the specified user. If the value of the User variable is numeric and does not appear as a login name in the /etc/passwd file, it is interpreted as a user ID.
  • -xdev — Always evaluates to the value True. Prevents the find command from traversing a file system different from the one specified by the Path parameter.

These expressions can be combined by using the following operators in the order of decreasing precedence:

  1. ( Expression ) - A parenthetic group of expressions and operators (parentheses are special to the shell and require the backslash-escape sequence).

  2. ! Expression - The negation of an expression ('!' is the unary NOT operator).

  3. Expression [ -a ] Expression - Concatenation of expressions (the AND operation is implied by the juxtaposition of two primaries or might be explicitly stated as -a).

  4. Expression -o Expression - Alternation of primaries; -o is the OR operator. The second expression is not evaluated if the first expression is true.

Note: When you use the find and cpio commands together, you must use the -follow option and the -L option with the cpio command. Not using these two options together produces undesirable results. If expression is not present, -print as used in the default expression. For example, if the specified expression does not contain any of the primaries -exec, -ok, or -print, the expression is replaced by (given_expression) -print. The -user, -group, and -newer primaries each evaluate their respective arguments only once. Using a command that is specified by -exec or -ok does not affect subsequent primaries on the same file.

종료 상태

값 뜻
0 모든 Path 매개변수를 잘 탐색했습니다.
0보다 큼 오류가 났습니다.
영어 원문

This command returns the following exit values:

  • 0 — All Path parameters were traversed successfully.
  • >0 — An error occurred.

예제

  1. 파일 시스템 전체에서 기본 이름이 같은 파일을 모두 나열합니다. /(슬래시)부터 모든 하위 디렉터리를 찾아 이름이 .profile인 파일의 전체 경로를 씁니다. 시간을 아끼려면 파일이 있을 만한 디렉터리로 범위를 좁히는 것이 좋습니다.
bash
find / -name .profile -print
  1. 현재 디렉터리 트리에서 특정 권한 코드를 가진 파일을 나열합니다. 소유자 읽기·쓰기 권한만 있는 파일의 이름을 보여 줍니다. .(점)은 현재 디렉터리와 그 하위 디렉터리를 찾으라는 뜻입니다.
bash
find . -perm 0600 -print
  1. 여러 디렉터리에서 특정 권한을 가진 파일을 찾습니다. 소유자 읽기·쓰기 권한이 있고 다른 권한도 있을 수 있는 파일의 이름을 보여 줍니다. 앞의 예의 -perm 0600은 권한이 정확히 0600인 파일만 고르지만, -perm -0600은 0600이 허용하는 접근에 더해 다른 접근도 허용하는 파일을 고릅니다. 0622나 0744도 맞습니다.
bash
find manual clients proposals -perm -0600 -print
  1. 현재 디렉터리에서 지난 24시간 안에 변경된 파일을 모두 나열합니다.
bash
find . -ctime 1 -print
  1. 링크가 여럿인 일반 파일을 찾습니다. 링크가 하나보다 많은(-links +1) 일반 파일(-type f)의 이름을 보여 줍니다. 디렉터리는 부모 디렉터리의 항목과 자기 . 항목으로 링크가 적어도 둘이라는 점에 주의합니다.
bash
find . -type f -links +1 -print
  1. 경로 이름에 find가 들어 있는, 접근할 수 있는 파일을 모두 찾습니다.
bash
find . -name '*find*' -print
  1. NFS로 마운트되지 않은 곳에서 일주일 넘게 접근하지 않은 a.out이나 *.o 파일을 모두 지웁니다. 일주일(24시간 일곱 번)보다 오래 접근하지 않은 파일을 대상으로 하려면 -atime에 +7을 씁니다.
bash
find / \( -name a.out -o -name '*.o' \) -atime +7 ! -fstype nfs -exec rm {} \;
  1. 현재 디렉터리 아래의 모든 파일 경로를 출력하되, SCCS라는 디렉터리와 그 안의 파일은 뺍니다. 둘째 명령은 SCCS 디렉터리 이름까지 포함해 출력합니다.
bash
find . -name SCCS -prune -o -print
find . -print -name SCCS -prune
  1. 길이가 정확히 414바이트인 파일을 모두 찾습니다.
bash
find . -size 414c -print
  1. 홈 디렉터리에서 확장자가 .c인 파일을 모두 찾아 지웁니다. find가 .c 파일을 찾을 때마다 rm이 그 파일을 지웁니다. -exec의 매개변수는 rm 명령 하나이고, {}는 현재 경로 이름입니다.
bash
find /u/arnold -name "*.c" -exec rm {} \;
  1. dirlink가 디렉터리 dir을 가리키는 심볼릭 링크일 때, 명령줄의 dirlink를 통해 dir의 파일을 나열합니다.
bash
find -H dirlink -print
  1. 같은 상황에서, dir 아래의 파일 계층을 심볼릭 링크까지 따라가며 dirlink의 파일을 나열합니다.
bash
find -L dirlink -print
  1. 심볼릭 링크 dirlink가 가리키는 dir1이 dir2보다 새로운지 알아봅니다. -H를 썼으므로 시간 정보는 dirlink가 아니라 링크를 따라가 찾은 dir1에서 가져옵니다.
bash
find -H dirlink -newer dir2
  1. 현재 디렉터리의 파일을 사용자·그룹 이름을 줄이지 않은 ls 형식으로 나열합니다.
bash
find . -ls -long
  1. 현재 디렉터리에서 ACL이나 EA가 있는 파일을 나열합니다.
bash
find . -ea
  1. 60분 안에 수정된 파일을 나열합니다.
bash
find . -mmin -60
영어 원문
  1. To list all files in the file system with a specified base file name, type:
find / -name .profile -print

This command searches the entire file system and writes the complete path names of all files named .profile. The / (slash) instructs the find command to search the root directory and all of its subdirectories. In order not to waste time, it is best to limit the search by specifying the directories where you think the files might be.

  1. To list files that have a specific permission code in the current directory tree, type:
find . -perm 0600 -print

This command lists the names of the files that have only owner-read and owner-write permission. The . (dot) instructs the find command to search the current directory and its subdirectories. See the chmod command for an explanation of permission codes.

  1. To search several directories for files with certain permission codes, type:
find manual clients proposals -perm -0600 -print

This command lists the names of the files that have owner-read and owner-write permissions and possibly other permissions. The manual, clients, and proposals directories and their subdirectories are searched. In the previous example, -perm 0600 selects only files with permission codes that match 0600 exactly. In this example, -perm -0600 selects files with permission codes that allow the accesses that are indicated by 0600 and other accesses above the 0600 level. It also matches the permission codes 0622 and 0744.

  1. To list all files in the current directory that are changed during the current 24-hour period, type:
find . -ctime 1 -print
  1. To search for regular files with multiple links, type:
find . -type f -links +1 -print

This command lists the names of the ordinary files (-type f) that have more than one link (-links +1).

Note: Every directory has at least two links: the entry in its parent directory and its own . (dot) entry. The ln command explains multiple file links.

  1. To find all accessible files whose path name contains find, type:
find . -name ’*find*’ -print
  1. To remove all files named a.out or *.o that are not accessed for a week and that are not mounted by using nfs, type:
find / \( -name a.out -o -name ’*.o’ \) -atime +7 ! -fstype nfs -exec rm {} \;

Note: The number that is used within the -atime expression is +7. It is the correct entry if you want the command to act on files that are not accessed for more than a week (seven 24-hour periods).

  1. To print the path names of all files in or below the current directory, except the directories named SCCS or files in the SCCS directories, type:
find . -name SCCS -prune -o -print

To print the path names of all files in or below the current directory, including the names of SCCS directories, type:

find . -print -name SCCS -prune
  1. To search for all files that are exactly 414 bytes long, type:
find . -size 414c -print
  1. To find and remove every file in your home directory with the .c suffix, type:
find /u/arnold -name "*.c" -exec rm {} \;

Every time the find command identifies a file with the .c suffix, the rm command deletes that file. The rm command is the only parameter that is specified for the -exec expression. The (braces) represent the current path name.

  1. In this example, dirlink is a symbolic link to the directory dir. To list the files in dir by referring to the symbolic link dirlink on the command line, type:
find -H dirlink -print
  1. In this example, dirlink is a symbolic link to the directory dir. To list the files in dirlink, traversing the file hierarchy under dir including any symbolic links, type:
find -L dirlink -print
  1. To determine whether the file dir1 referred by the symbolic link dirlink is newer than dir2, type:
find -H dirlink -newer dir2

Note: Because the -H flag is used, time data is collected not from dirlink but instead from dir1, which is found by traversing the symbolic link.

  1. To produce a listing of files in the current directory in ls format with expanded user and group name, type:
find . -ls -long
  1. To list the files with ACL/EA set in current directory, type:
find . -ea
  1. To list the files that are modified within 60 minutes, type:
find . -mmin -60

파일

파일 설명
/usr/bin/find find 명령이 들어 있습니다.
/bin/find find 명령에 대한 심볼릭 링크입니다.
/etc/group 알려진 모든 그룹의 목록이 들어 있습니다.
/etc/passwd 알려진 모든 사용자의 목록이 들어 있습니다.

관련 명령어: ln

영어 원문
  • /usr/bin/find — Contains the find command.
  • /bin/find — Symbolic link to the find command.
  • /etc/group — Contains a list of all known groups.
  • /etc/passwd — Contains a list of all known users.

Related information:

  • ln command
  • Backup methods
  • Types of files
  • Input and output redirection
  • Shells command

리눅스(GNU)와 다른 점

항목 AIX 5.3·6.1 GNU find
-atime·-ctime·-mtime의 기본 UNIX03 이전 동작이 기본(XPG_SUS_ENV·XPG_UNIX98로 바꿈) POSIX 동작
-ea, -long, -cpio 있음 없음
-size의 단위 블록(512바이트)과 c(바이트)만 k, M, G 같은 단위도 받음
경로 생략 find -H dirlink처럼 경로 앞에 플래그만 둠, 경로는 꼭 지정 경로를 생략하면 .

AIX 5.3·6.1 문서에는 -iname, -regex, -maxdepth·-mindepth, -delete, -empty, -printf, -path 같은 GNU 식이 없습니다. 깊이를 제한하려면 -prune을 씁니다.