"Find"의 두 판 사이의 차이

ph
이동: 둘러보기, 검색
 
(사용자 2명의 중간 판 27개는 보이지 않습니다)
1번째 줄: 1번째 줄:
* 모든 실행파일 찾기
+
== find only the leaf directories ==
 +
find dir -type d -links 2
 +
<blockquote>a directory has a link for each subdirectory in it, a link from its parent and a link to self, thus a count of 2 link if it has no subdirectories</blockquote>
 +
historical reason이라고 함. [https://unix.stackexchange.com/a/101536/31363 좋은 설명]
 +
 
 +
==hidden file or path 제외==
 +
  find . -not -path '*/\.*’
 +
[https://askubuntu.com/a/318211/400331]
 +
 
 +
==특정 디렉토리 제외==
 +
find . -path ./misc -prune -o -name '*.txt' -print
 +
find . -type d \( -path dir1 -o -path dir2 -o -path dir3 \) -prune -o -print
 +
[http://stackoverflow.com/a/4210072/766330]
 +
-prune True;  if  the  file is a directory, do not descend into it.  If
 +
              -depth is given, false;  no  effect.  Because  -delete  implies
 +
              -depth, you cannot usefully use -prune and -delete together.
 +
 
 +
== 모든 실행파일 찾기==
 
일단 file * | grep executable 이 제일 간단함. find명령으로는
 
일단 file * | grep executable 이 제일 간단함. find명령으로는
 
  find . -depth 1 -perm -u+x ! -type d
 
  find . -depth 1 -perm -u+x ! -type d
 
symbolic link까지 찾는다는게 문제. ! -type l 로 거를 수 있으나 ln의 source file이 executable일 수 있음.
 
symbolic link까지 찾는다는게 문제. ! -type l 로 거를 수 있으나 ln의 source file이 executable일 수 있음.
* 오늘 바뀐 파일 찾기
+
이게 더 낫다.
<syntaxhighlight lang="bash">
+
find . -executable -type f
$ touch -t `date +%m%d0000` creteria ;  find . -newer creteria -type f
+
 
</syntaxhighlight>
+
== find only ASCII text file ==
* 찾아서 etags
+
find . -type f -exec grep -Iq . {} \; -and -print
  find . -name '*.cpp' -or -name '*.h' | xargs etags --append
+
[http://stackoverflow.com/a/13659891/766330]
 +
 
 +
== 오늘 바뀐 파일 찾기==
 +
$ touch -t `date +%m%d0000` creteria ;  find . -newer creteria -type f
 +
 
 +
== 최근 1분간 바뀐 파일 찾기==
 +
$ find . -mmin -1
 +
 
 +
== 최근 24시간동안 바뀐 파일 찾기 ==
 +
$ find /<filesystem_name> -xdev -mtime 0 -ls
 +
[http://www-903.ibm.com/kr/techinfo/pseries/tech/techdoc4.html#bb]
 +
 
 +
== 찾아서 etags==
 +
find . -name '*.cpp' -or -name '*.h' | xargs etags --append
 
[http://www.gnu.org/software/libtool/manual/emacs/Create-Tags-Table.html#Create-Tags-Table emacs manual]에는  
 
[http://www.gnu.org/software/libtool/manual/emacs/Create-Tags-Table.html#Create-Tags-Table emacs manual]에는  
 
  find . -name "*.[chCH]" -print | etags -
 
  find . -name "*.[chCH]" -print | etags -
* find symbolic link files those are not containing 'external' string in their full path.
+
 
<syntaxhighlight lang="bash">
+
==크기가 큰 파일 찾아 sort==
 +
find / -xdev -size  +2048 -ls |sort -r  +6
 +
#(+6 option did not work on CentOS 6)
 +
[http://www-903.ibm.com/kr/techinfo/pseries/tech/techdoc4.html#bb]
 +
 
 +
== find symbolic link files those are not containing 'external' string in their full path.==
 
  find . -wholename '*external*' -prune -o -type l -exec ls -l '{}' \;
 
  find . -wholename '*external*' -prune -o -type l -exec ls -l '{}' \;
</syntaxhighlight>
+
 +
$ # prints only one line
 +
$ find / -name blabla\* -print -quit
 +
$
 +
$
 +
$ # execute two (or more) statements
 +
$ # simple. use two (or more) exec commands.
 +
$ find . -name \*jpg -o -name \*JPG -exec echo \{} \; -exec face-detect-using-xml.exe -x cascade.xml \{} \;
 +
 
 +
== run multiple exec ==
 +
find . -name "*.txt" -exec echo {} \; -exec grep banana {} \;
 +
첫번째 명령 성공해야 두번째도 실행.
 +
무조건 하려면 아래와 같이.
 +
find . -name "*.txt" \( -exec echo {} \; -o -exec true \; \) -exec grep banana {} \; [http://stackoverflow.com/a/6043896/766330]
 +
find . -type d -exec sh -c "echo -n {}; echo -n ' x '; echo {}" \;
 +
[http://stackoverflow.com/a/13764308/766330]<br>
 +
다음과 같이 하는수도 있다.
 +
find ... | while read -r file; do
 +
    echo "look at my $file, my $file is amazing";
 +
done
 +
또는
 +
while read -r file; do
 +
    echo "look at my $file, my $file is amazing";
 +
done <<< "$(find ...)"
 +
[http://stackoverflow.com/a/37638504/766330]
 +
 
 +
==실행가능파일 찾기==
 +
find . -executable
 +
find . -perm /u=x,g=x,o=x
 +
두번째는 문법이 생소하다.
 +
 
 +
[https://superuser.com/a/39100/108174]

2019년 4월 15일 (월) 15:38 기준 최신판

find only the leaf directories

find dir -type d -links 2

a directory has a link for each subdirectory in it, a link from its parent and a link to self, thus a count of 2 link if it has no subdirectories

historical reason이라고 함. 좋은 설명

hidden file or path 제외

 find . -not -path '*/\.*’

[1]

특정 디렉토리 제외

find . -path ./misc -prune -o -name '*.txt' -print
find . -type d \( -path dir1 -o -path dir2 -o -path dir3 \) -prune -o -print

[2]

-prune True;  if  the  file is a directory, do not descend into it.  If
             -depth is given, false;  no  effect.   Because  -delete  implies
             -depth, you cannot usefully use -prune and -delete together.

모든 실행파일 찾기

일단 file * | grep executable 이 제일 간단함. find명령으로는

find . -depth 1 -perm -u+x ! -type d

symbolic link까지 찾는다는게 문제. ! -type l 로 거를 수 있으나 ln의 source file이 executable일 수 있음. 이게 더 낫다.

find . -executable -type f

find only ASCII text file

find . -type f -exec grep -Iq . {} \; -and -print

[3]

오늘 바뀐 파일 찾기

$ touch -t `date +%m%d0000` creteria ;  find . -newer creteria -type f

최근 1분간 바뀐 파일 찾기

$ find . -mmin -1

최근 24시간동안 바뀐 파일 찾기

$ find /<filesystem_name> -xdev -mtime 0 -ls

[4]

찾아서 etags

find . -name '*.cpp' -or -name '*.h' | xargs etags --append

emacs manual에는

find . -name "*.[chCH]" -print | etags -

크기가 큰 파일 찾아 sort

find / -xdev -size  +2048 -ls |sort -r  +6
#(+6 option did not work on CentOS 6)

[5]

find symbolic link files those are not containing 'external' string in their full path.

find . -wholename '*external*' -prune -o -type l -exec ls -l '{}' \;

$ # prints only one line
$ find / -name blabla\* -print -quit
$
$
$ # execute two (or more) statements
$ # simple. use two (or more) exec commands.
$ find . -name \*jpg -o -name \*JPG -exec echo \{} \; -exec face-detect-using-xml.exe -x cascade.xml \{} \;

run multiple exec

find . -name "*.txt" -exec echo {} \; -exec grep banana {} \;

첫번째 명령 성공해야 두번째도 실행. 무조건 하려면 아래와 같이.

find . -name "*.txt" \( -exec echo {} \; -o -exec true \; \) -exec grep banana {} \; [6]
find . -type d -exec sh -c "echo -n {}; echo -n ' x '; echo {}" \;

[7]
다음과 같이 하는수도 있다.

find ... | while read -r file; do
   echo "look at my $file, my $file is amazing";
done

또는

while read -r file; do
   echo "look at my $file, my $file is amazing";
done <<< "$(find ...)"

[8]

실행가능파일 찾기

find . -executable
find . -perm /u=x,g=x,o=x

두번째는 문법이 생소하다.

[9]