"리눅스 find"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
5번째 줄: 5번째 줄:
*파일, 디렉토리 검색 리눅스 명령어
*파일, 디렉토리 검색 리눅스 명령어


<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki yum]# find
[root@zetawiki yum]# find
.
.
14번째 줄: 14번째 줄:
./vars
./vars
./protected.d
./protected.d
</source>
</syntaxhighlight>


==리눅스 파일 찾기==
==리눅스 파일 찾기==
{{참고|리눅스 파일 찾기}}
{{참고|리눅스 파일 찾기}}
<source lang='bash'>
<syntaxhighlight lang='bash'>
find / -name 파일명
find / -name 파일명
</source>
</syntaxhighlight>
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# find / -name httpd.conf
[root@zetawiki ~]# find / -name httpd.conf
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/httpd.conf
</source>
</syntaxhighlight>


==하위 디렉토리 목록==
==하위 디렉토리 목록==
{{참고|리눅스 하위디렉토리 목록 보기}}
{{참고|리눅스 하위디렉토리 목록 보기}}
*하위디렉토리 전체(recursive)
*하위디렉토리 전체(recursive)
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki vector]# find . -type d
[root@zetawiki vector]# find . -type d
.
.
35번째 줄: 35번째 줄:
./images/preferences
./images/preferences
./components
./components
</source>
</syntaxhighlight>


*1단계 하위디렉토리
*1단계 하위디렉토리
<source lang='console'>
<syntaxhighlight lang='console'>
[root@koreanpol vector]# find . -maxdepth 1 -type d
[root@koreanpol vector]# find . -maxdepth 1 -type d
.
.
./images
./images
./components
./components
</source>
</syntaxhighlight>


==두 개의 파일 동시에 찾기==
==두 개의 파일 동시에 찾기==
* "-o" 를 사용하여 두개의 파일을 한 번에 찾을 수 있음
* "-o" 를 사용하여 두개의 파일을 한 번에 찾을 수 있음
<source lang="console">
<syntaxhighlight lang="console">
[root@koreanpol vector]# find -name "a.c" -o -name "b.c"
[root@koreanpol vector]# find -name "a.c" -o -name "b.c"
./a.c
./a.c
./b.c
./b.c
</source>
</syntaxhighlight>


==특정 파일을 제외하고 찾기==
==특정 파일을 제외하고 찾기==
* "!"를 사용하여 특정 파일을 제외하여 찾을 수 있음
* "!"를 사용하여 특정 파일을 제외하여 찾을 수 있음
<source lang="console">
<syntaxhighlight lang="console">
[root@koreanpol vector]# find . ! -name "*.txt"
[root@koreanpol vector]# find . ! -name "*.txt"
.
.
./a.c
./a.c
./b.c
./b.c
</source>
</syntaxhighlight>
: → 현재 디렉토리에서 텍스트 파일 형식을 제외한 다른 모든 파일을 찾음
: → 현재 디렉토리에서 텍스트 파일 형식을 제외한 다른 모든 파일을 찾음


==file 명령과 함께 현재 디렉토리에서 파일 찾기==
==file 명령과 함께 현재 디렉토리에서 파일 찾기==
* file 명령과 함께 현재 디렉토리에서 파일을 찾기 위한 명령
* file 명령과 함께 현재 디렉토리에서 파일을 찾기 위한 명령
<source lang="bash">
<syntaxhighlight lang="bash">
find . -type f -exec file '{}' \;
find . -type f -exec file '{}' \;
</source>
</syntaxhighlight>


*1. 분석해보면 '''find . -type f''' 는 현재 디렉토리에서 파일을 찾는 명령
*1. 분석해보면 '''find . -type f''' 는 현재 디렉토리에서 파일을 찾는 명령
<source lang="console">
<syntaxhighlight lang="console">
john@zetawiki:~$ ll
john@zetawiki:~$ ll
total 16
total 16
83번째 줄: 83번째 줄:
./a.c
./a.c
./b.c
./b.c
</source>
</syntaxhighlight>
:→현재 디렉토리에 a.c, b.c, c.c 파일과 d라는 디렉토리가 있음.
:→현재 디렉토리에 a.c, b.c, c.c 파일과 d라는 디렉토리가 있음.
:파일 형태만 출력 했기 때문에 디렉토리 d를 제외한 a.c, b.c, c.c 파일이 출력이됨
:파일 형태만 출력 했기 때문에 디렉토리 d를 제외한 a.c, b.c, c.c 파일이 출력이됨
92번째 줄: 92번째 줄:


*3. 전체 명령 출력
*3. 전체 명령 출력
<source lang="console">
<syntaxhighlight lang="console">
john@zetawiki:~$ ll
john@zetawiki:~$ ll
total 24
total 24
105번째 줄: 105번째 줄:
./a.c: C source, ASCII text
./a.c: C source, ASCII text
./b.c: C source, ASCII text
./b.c: C source, ASCII text
</source>
</syntaxhighlight>
:→file 명령과 함께 find가 실행 된 것을 확인 할 수 있음
:→file 명령과 함께 find가 실행 된 것을 확인 할 수 있음


※ file 명령 실행
※ file 명령 실행
<source lang="console">
<syntaxhighlight lang="console">
john@zetawiki:~$ file a.c
john@zetawiki:~$ file a.c
a.c: C source, ASCII text
a.c: C source, ASCII text
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2021년 9월 24일 (금) 23:24 판

  다른 뜻에 대해서는 indexOf 문서를 참조하십시오.

1 개요

리눅스 find
/bin/find
  • 파일, 디렉토리 검색 리눅스 명령어
[root@zetawiki yum]# find
.
./version-groups.conf
./pluginconf.d
./pluginconf.d/security.conf
./pluginconf.d/fastestmirror.conf
./vars
./protected.d

2 리눅스 파일 찾기

find / -name 파일명
[root@zetawiki ~]# find / -name httpd.conf
/etc/httpd/conf/httpd.conf

3 하위 디렉토리 목록

  • 하위디렉토리 전체(recursive)
[root@zetawiki vector]# find . -type d
.
./images
./images/preferences
./components
  • 1단계 하위디렉토리
[root@koreanpol vector]# find . -maxdepth 1 -type d
.
./images
./components

4 두 개의 파일 동시에 찾기

  • "-o" 를 사용하여 두개의 파일을 한 번에 찾을 수 있음
[root@koreanpol vector]# find -name "a.c" -o -name "b.c"
./a.c
./b.c

5 특정 파일을 제외하고 찾기

  • "!"를 사용하여 특정 파일을 제외하여 찾을 수 있음
[root@koreanpol vector]# find . ! -name "*.txt"
.
./a.c
./b.c
→ 현재 디렉토리에서 텍스트 파일 형식을 제외한 다른 모든 파일을 찾음

6 file 명령과 함께 현재 디렉토리에서 파일 찾기

  • file 명령과 함께 현재 디렉토리에서 파일을 찾기 위한 명령
find . -type f -exec file '{}' \;
  • 1. 분석해보면 find . -type f 는 현재 디렉토리에서 파일을 찾는 명령
john@zetawiki:~$ ll
total 16
drwxrwxr-x  3 john john 4096 Feb 14 13:53 ./
drwxr-xr-x 12 john john 4096 Feb 14 13:52 ../
-rw-rw-r--  1 john john   69 Feb 14 13:52 a.c
-rw-rw-r--  1 john john    0 Feb 14 13:52 b.c
-rw-rw-r--  1 john john    0 Feb 14 13:53 c.c
drwxrwxr-x  2 john john 4096 Feb 14 13:53 d/
john@zetawiki:~$ find . -type f
./c.c
./a.c
./b.c
→현재 디렉토리에 a.c, b.c, c.c 파일과 d라는 디렉토리가 있음.
파일 형태만 출력 했기 때문에 디렉토리 d를 제외한 a.c, b.c, c.c 파일이 출력이됨
  • 2. -exec file '{}' \;는 각각의 파일에 대해서 file 명령을 실행하고 그 결과 출력을 {}에 위치 시킴
{}의 양옆에 위치한 따옴표는 쉘 스크립트의 명령에 따른 명령 혼돈을 방지하기 위함임.
마지막의 세미콜론은 백슬러시를 통해 출력 값에 의한 쉘 스크립트에서의 명령 혼돈을 막아줌
  • 3. 전체 명령 출력
john@zetawiki:~$ ll
total 24
drwxrwxr-x  3 john john 4096 Feb 14 14:06 ./
drwxr-xr-x 12 john john 4096 Feb 14 14:06 ../
-rw-rw-r--  1 john john   69 Feb 14 13:52 a.c
-rw-rw-r--  1 john john   19 Feb 14 14:06 b.c
-rw-rw-r--  1 john john   38 Feb 14 14:06 c.c
drwxrwxr-x  2 john john 4096 Feb 14 13:53 d/
john@zetawiki:~$ find . -type f -exec file '{}' \;
./c.c: C source, ASCII text
./a.c: C source, ASCII text
./b.c: C source, ASCII text
→file 명령과 함께 find가 실행 된 것을 확인 할 수 있음

※ file 명령 실행

john@zetawiki:~$ file a.c
a.c: C source, ASCII text

7 같이 보기

8 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}