'find'에 해당되는 글 1건

  1. 2010.01.11 find + xargs + ls 명령어 몇가지 활용
Linux/Unix2010. 1. 11. 18:01
목차
1. 가장 일반적인 find 명령어

2. find 명령어 일반적인 옵션
  2-1. 사용법 개요
  2-2. 일반적으로 표현식 옵션 구분
  3-3. 자주 사용되는 표현식 옵션
  3-4. path(find 명령어 다음의 path)
  3-5. 표현식-연산자

3. 예제
  3-1. 다른 명령어와 결합형태(ls,xargs)
  3-2. 퍼미션 관련 예제
  3-3. 유저와 관련된 예제
  3-4. 팁
  - 최근 하루(1) 동안(-)에 변경(change)된 파일을 찾을려면(-ctime)?
  - 오래된 파일을 찾을려면(30일 이상 수정(modify))되지 않은)?
  - 최근 30일(30) 안에(-) 접근(access)하지 않은 파일과 디렉토리를 리스트로 만들려면(-atime)?
  - 자신의 홈디렉토리에서 만 검색하려면?
  - 서브 디렉토리로 내려가지 않고 현재 디렉토리에서만 검색하려면?
  - 특정 유저(foobar) 소유의 파일을 찾을려면?
  - 퍼미션이 777인 파일을 찾을려면 ?
  - others에게 쓰기 권한이 있는 파일을 찾을려면?
  - others에게 쓰기 권한이 있는 파일을 찾아 쓰기 권한을 없애려면?
  - 유저이름과 그룹이름이 없는 파일을 찾을려면?
  - 빈 파일을 찾을려면?
  - 파일크기가 100M 이상된 파일을 찾을려면?
  - *.bak 파일을 찾아 지울려면?
  - *.bak 파일을 찾아 특정 디렉토리로 옮길려면?
  - 디렉토리 만 찾을려면?
  - root권한으로 실행되는 파일을 찾을려면?
  - 다른 파일시스템을 검색하지 않을려면?
  - 파일이름에 공백이 들어간 파일을 찾을려면?
  - 숨겨진(hidden) 파일을 찾을려면?
  - 같은 이름을 가진 디렉토리를 찾을려면?
  - 잘못된 링크를 찾을려면?

4. find 명령어에 대해서 좀더 알아보려면?

------------------------------------------------------------

1. 가장 일반적인 find 명령어

	# find /path -name "foobar" -print

제일 먼저(?) 배우는 형식이 아닌가 쉽군요.


2. find 명령어 일반적인 옵션

2-1. 사용법 개요

find 명령어 사용법 보기 :

# find --help
# man find (직접 입력해 보세요. 내용이 너무 많아서..)

사용법 : find [path...] [expression]
기본값 : default path는 현재 디렉토리;  default expression은 -print

표현식(expression) 구성 :
operators (decreasing precedence; -and is implicit where no others are given):
      ( EXPR ) ! EXPR -not EXPR EXPR1 -a EXPR2 EXPR1 -and EXPR2
      EXPR1 -o EXPR2 EXPR1 -or EXPR2 EXPR1 , EXPR2
options (always true): -daystart -depth -follow --help
      -maxdepth LEVELS -mindepth LEVELS -mount -noleaf --version -xdev
tests (N can be +N or -N or N):
      -amin N -anewer FILE -atime N -cmin N
      -cnewer FILE -ctime N -empty -false -fstype TYPE -gid N -group NAME
      -ilname PATTERN -iname PATTERN -inum N -ipath PATTERN -iregex PATTERN
      -links N -lname PATTERN -mmin N -mtime N -name PATTERN -newer FILE
      -nouser -nogroup -path PATTERN -perm [+-]MODE -regex PATTERN
      -size N[bckw] -true -type [bcdpfls] -uid N -used N -user NAME
      -xtype [bcdpfls]
actions:
      -exec COMMAND ; -fprint FILE -fprint0 FILE -fprintf FILE FORMAT
      -ok COMMAND ; -print -print0 -printf FORMAT -prune -ls

간단하게 몇가지만 알아보죠...
(자세한 사용설명은 꼭 man 페이지를 읽어보세요....한글은 없군요..T.T)


2-2. 일반적으로 표현식 옵션 구분

  -a'xxxx'
		'xxxx'에 대한 Access(접근)
  -c'xxxx'
		'xxxx'에 대한 Changes(변경), 마지막으로 Access한 경우 변경됨
  -m'xxxx'
		'xxxx'에 대한 Modify(수정), 파일내용 자체 수정한 경우
  -i'xxxx'
		'xxxx'(inum 제외)에 대한 Insensitive(대소문자 구분없이)

3-3. 자주 사용되는 표현식 옵션

  N
		정확하게 N과 일치
  +N
		N 보다 큰 경우
  -N
		N 보다 작은 경우
  -name PATTERN
		PATTERN에 일치하는 파일 찾기, 와일드카드 문자 사용가능
  -iname PATTERN
		PATTERN에 일치하지 않은(insensitive) 파일 찾기
  -perm [+-]mode
		PERMission('mode')에 해당되는 파일 찾기, ls와 결합 가능
  -type [bcdpfls]
		b(블럭파일), c(특정 문자), d(디렉토리), p(파이프),
		f(정규표현 일반파일), l(링크), s(소켓) 유형의 파일 찾기
  -size N[bckw]
		파일 크기가 N 인 파일 찾기
		b(블럭-기본값), c(bytes), k(kbytes),
		w(2바이트 단어)
  -user NAME
		NAME은 유저이름이거나 UID
  -atime N
		N*24 시간 동안에 Access 한 파일
  -ctime N
		N*24 시간 동안에 Changes 한 파일(내용수정이 아니고 읽기모드도 Changes됨)
  -mtime N
		N*24 시간 동안에 Modify 한 파일
  -empty
		파일이 비어 있고(0 bytes), 정규식 파일이거나 디렉토리
  -newer FILE
		FILE 보다 최근에 갱신된 파일
  -path PATTERN
		path가 PATTERN과 일치하는 path에 대해서 검색
  -regex PATTERN
		파일이름이 PATTERN에 일치하는 정규식에 대해서 검색
  -inum N
		inode N을 갖는 파일
  -nouser,-nogroup
		USER나 GROUP에 이름이 없는 파일 검색(UID,GID만 있는 파일)
  -exec COMMAND
		검색된 파일을 찾으면 COMMAND 명령을 실행한다.
		COMMAND 인자(검색된 파일)는 {}으로 사용하며,
		이때 COMMAND 끝은 \;(;이 아님)을 사용해야 한다. 즉 명령구분
		문자인 ';'을 탈출(\)시켜줘야 한다.
  -ok COMMAND
		-exec COMMAND와 같지만 COMMAND를 실행하기 전에 확인을 요청한다.

3-4. path(find 명령어 다음의 path)
  .
		현재 디렉토리(기본값이므로 생략해도 됨)
  `pwd`
		현재 디렉토리와 결합(?) `은 ~문자가 있는 자판
  $(pwd)
		위의 `pwd`와 같거나 비슷함
  /
		최상위 루트 디렉토리에서 하위 모든 디렉토리
  /home
		특정 /home 디렉토리에서 하위 모든 디렉토리
  /{usr,home/{aaa,san2},var}
		/usr, /usr/home/aaa /usr/home/san2 /var

3-5. 표현식-연산자

  \( 표현식 \)
		'표현식'을 우선적으로 먼저 수행
		(와 )앞에 \를 넣어야 하며, '표현식'과 공백을 각각 둔다.
		\( A + B \) * \( C + D \) 와 같이 \(, \)안을 우선적으로 수행
  ! 표현식 , -not 표현식
		'표현식'을 부정
  표현식1 -a 표현식2, 표현식1 -and 표현식2
		표현식1과 표현식2의 AND 연산
  표현식1 -o 표현식2, 표현식1 -or 표현식2
		표현식1과 표현식2의 OR 연산


3. 예제

3-1. 다른 명령어와 결합 형태(ls,xargs)

찾는 것 그 차체 만으로 만족(?) 할 수 도 있지만 그 결과에 대해서
어떤 행동(Actions)을 취할 필요가 있습니다.

  형태1. -exec 이용시

		# find ..... -exec COMMAND {} \;

  형태2. xargs 명령어로 표준 입력받아 COMMAND 수행

		# find ..... | xargs COMMAND

  형태3. ls 명령어로 최종 결과 출력

		# ls -l `find .....[COMMAND]`
		또는
		# find .... ls
		(ls는 ls -dils와 같음)

  xargs
	xargs rpm 정보보기
	# rpm -qi `rpm -qf $(which xargs)`
	또는
	# rpm -qf `which xargs` | xargs rpm -qi

즉, find 결과에 대해서,

형태1은 -exec를 사용하여 그 인자를 {}로 사용하고,

형태2는 xargs 명령어로 find에서 넘어온 결과(표준출력)에 대해서 COMMAND를 실행하고,

형태3은 오른쪽의 find 결과물에 대해서 ls 명령어를 실행합니다.
간혹 '/bin/ls Argument list too long'이라는 에러를 낸 경우도 있습니다.
이는 검색조건에 너무 많은 와일드카드 문자로 찾을 경우에 그렇습니다.
이를 테면 /*/*/*.*/.*,

`은 ~문자가 있는 자판(역인용부호).

ls -l 명령어를 사용할 경우, 찾는 결과가 없다면 모두 출력됩니다.
(ls -l와 같기 때문에)
ls 명령어와 마찬가지로 다른 명령어(chmod, chmod)를 결합하여 사용할 경우 그 찾는
결과가 없다면 명령어에 대한 에러를 내겠죠.
(chmod 'null')과 같은 예..........

# find /{home,usr/{src,local/src}} -nouser -o -nogroup -exec ls -l {} \; -print | more
# find /{home,usr/{src,local/src}} -nouser -o -nogroup -print | xargs ls -l | more

위의 2개의 명령어 대해서 직접 테스트 해보세요...

전자의 경우, 아마 아무것도 출력되지 않을 겁니다.

# find /{home,usr/{src,local/src}} \( -nouser -o -nogroup \) -exec ls -l {} \; -print | more

위와 같이 해야 맞겠죠...(우선순위)

후자의 경우도 마찬가지로 다음과 같이 우선순위를 정해놓아야 겠지요..
아마 원하는 출력이 이 경우일 것 같군요.

# find /{home,usr/{src,local/src}} \( -nouser -o -nogroup \) -print | xargs ls -l | more


3-2. 퍼미션 관련 예제

othesrs에 쓰기(w:2) 권한이 있는 모든(-기호를 붙임) 파일 리스트를 찾을려면?

# find `pwd` -perm -2 -print | xargs ls -l

여기에서 2는
퍼미션이 -------w- 와 일치하는 파일이며 -의 의미는 rwx-중 하나.

왜 2인가요?
만약 퍼미션이 755 이라면,

   700 : rwx------ : user
    50 : ---r-x--- : group
     5 : ------r-x : others
   ------------------------
   755 : rwxr-xr-x : others는 읽기와 실행 권한

따라서 others의 권한은 8진수로 5(r+x)이다.

그렇다면, others가 쓰기(w:2) 권한은 당연히 -------w-

그룹이나 others에게 쓰기 권한이 있는 파일일 경우

	-perm -20 -o -perm -2

그룹과 others에게 모두 쓰기 권한이 있는 파일일 경우

	-perm -22

[others에게 w 권한이 있는 파일에 w 권한 없애기]

방법1)
  1. others에게 w 권한이 있는 파일 리스트 출력

	# find `pwd` -perm -2 -print | xargs ls -l | more
	(만약 매치되는 리스트가 없다면 전부 출력함)

  2. others에게 w 권한을 없애기

	# find `pwd` -perm -2 -print | xargs chmod o-w
	(만약 매치되는 리스트가 없다면 chmod에 에러를 냄)

방법2) 방법1)의 과정을 한꺼번에 할 경우

  # find `pwd` -perm -2 -exec chmod o-w {} \; -print | xargs ls -l
  또는
  # ls -l `find $(pwd) -perm -2 -print | xargs chmod o-rwx` | more

  이 경우는 퍼미션이 조정된 결과를 출력함.


3-3. 유저와 관련된 예제

UID와 GID에 대한 유저가 없는 파일을 root.root로 바꾸어 보죠.

1) 먼저 리스트를 출력해 보자.(확인해야하니깐)

  # find . \( -nouser -o -nogroup \) -print | xargs ls -l | more

2) 확인했으면, chown root.root 명령을 내리자.

  # find . \( -nouser -o -nogroup \) -print | xargs chown root.root | more
  또는
  # find . \( -nouser -o -nogroup \) -exec chown root.root {} \; -print | xargs ls -l
  (chown root.root 의 결과를 ls -l)


3-4. 유용한 팁

*주의) ***********************************************
  -a'xxxx'
		'xxxx'에 대한 Access(접근), 읽기
  -c'xxxx'
		'xxxx'에 대한 Changes(변경), 마지막으로 Access한 경우에도 변경됨
  -m'xxxx'
		'xxxx'에 대한 Modify(수정), 파일내용 자체 수정한 경우
*****************************************************

  - 최근 하루(1) 동안(-)에 변경(change)된 파일을 찾을려면(-ctime)?

	# find / -ctime -1 -a -type f | xargs ls -l | more

  - 오래된 파일을 찾을려면(30일 이상 수정(modify))되지 않은)?

	# find / -mtime +30 -print | more

  - 최근 30일(30) 안에(-) 접근(access)하지 않은 파일과 디렉토리를 리스트로 만들려면(-atime)?

	# find / ! \( -atime -30 -a \( -type d -o -type f \) \) | xargs ls -l > not_access.list

  - 자신의 홈디렉토리에서 만 검색하려면?

	# find $HOM ...
	또는
	# find ~root ...

  - 서브 디렉토리로 내려가지 않고 현재 디렉토리에서만 검색하려면?

	# find . -prune ...

  - 특정 유저(foobar) 소유의 파일을 찾을려면?

	# find / -user foobar -print | more

  - 퍼미션이 777인 파일을 찾을려면 ?

	# find / -perm 777 -print | xargs ls -l | more

  - others에게 쓰기 권한이 있는 파일을 찾을려면?

	# find / -perm -2 -print | xargs ls -l | more

  - others에게 쓰기 권한이 있는 파일을 찾아 쓰기 권한을 없애려면?

	# find / -perm -2 -print | xargs chmod o-w
	또는
	# find / -perm -2 -exec chmod o-w {} \; -print | xargs ls -l | more

  - 유저이름과 그룹이름이 없는 파일을 찾을려면?

	# find / \( -nouser -o -nogroup \) -print | more

  - 빈 파일을 찾을려면?

	# find / -empty -print | more
	또는
	# find / -size 0 -print | more

  - 파일크기가 100M 이상된 파일을 찾을려면?

	# find / -size +102400k -print | xargs ls -hl

  - *.bak 파일을 찾아 지울려면?

	# find / -name "*.bak" -exec rm -rf {} \;

  - *.bak 파일을 찾아 특정 디렉토리로 옮길려면?

	# mv `find . -name "*.bak"` /home/bak/

  - 디렉토리 만 찾을려면?

	# find . -type d ...

  - root권한으로 실행되는 파일을 찾을려면?

	# find / \( -user root -a -perm +4000 \) -print | xargs ls -l | more

  - 다른 파일시스템을 검색하지 않을려면?

	# find / -xdev ...

  - 파일이름에 공백이 들어간 파일을 찾을려면?

	# find / -name "* *" -print

  - 숨겨진(hidden) 파일을 찾을려면?

	# find / -name ".*" -print | more

  - 같은 이름을 가진 디렉토리를 찾을려면?

	# find / -type d -print | awk -F/ '{printf("%s\t%s\n",$NF,$0);}' | sort| more
	*주)'O'Reilly Unix Power Tools' 참고

  - 잘못된 링크를 찾을려면?

	# find . -type l -print | perl -nle '-e || print' | xargs ls -l
	*주)'O'Reilly Unix Power Tools' 참고


4. find 명령어에 대해서 좀더 알아보려면?

# man find

DESCRIPTION
       This  manual page documents the GNU version of find.  find
       searches the directory tree rooted at each given file name
       by  evaluating  the  given  expression from left to right,
       according to the rules of precedence (see  section  OPERA
       TORS),  until  the outcome is known (the left hand side is
       false for and operations, true for  or),	 at  which  point
       find moves on to the next file name.

       The first argument that begins with `-', `(', `)', `,', or
       `!' is taken to be the beginning of  the	 expression;  any
       arguments before it are paths to search, and any arguments
       after it are the rest of the expression.	 If no paths  are
       given, the current directory is used.  If no expression is
       given, the expression `-print' is used.

       find exits with status 0 if all files are  processed  suc
       cessfully, greater than 0 if errors occur.

EXPRESSIONS
       The expression is made up of options (which affect overall
       operation rather than the processing of a  specific  file,
       and  always  return  true),  tests (which return a true or
       false value), and actions (which	 have  side  effects  and
       return a true or false value), all separated by operators.
       -and is assumed where the operator  is  omitted.	  If  the
       expression  contains  no actions other than -prune, -print
       is performed on all files  for  which  the  expression  is
       true.

1) path(생략-앞부분에서 설명)

2) 표현식-연산자(생략-앞부분에서 설명)

3) 표현식-옵션 :
   options (always true):
       -daystart -depth -follow --help
       -maxdepth LEVELS -mindepth LEVELS -mount -noleaf --version -xdev

       All  options always return true.	 They always take effect,
       rather than being processed only when their place  in  the
       expression is reached.  Therefore, for clarity, it is best
       to place them at the beginning of the expression.

       -daystart
	      Measure times (for -amin,	 -atime,  -cmin,  -ctime,
	      -mmin,  and  -mtime)  from  the  beginning of today
	      rather than from 24 hours ago.

       -depth Process each directory's contents before the direc
	      tory itself.

       -follow
	      Dereference symbolic links.  Implies -noleaf.

       -help, --help
	      Print  a	summary of the command-line usage of find
	      and exit.

       -maxdepth levels
	      Descend at most  levels  (a  non-negative	 integer)
	      levels  of directories below the command line argu
	      ments.  `-maxdepth 0' means only	apply  the  tests
	      and actions to the command line arguments.

       -mindepth levels
	      Do  not  apply  any tests or actions at levels less
	      than levels (a non-negative  integer).   `-mindepth
	      1'  means process all files except the command line
	      arguments.

       -mount Don't descend directories on other filesystems.  An
	      alternate	 name  for  -xdev, for compatibility with
	      some other versions of find.

       -noleaf
	      Do not optimize by assuming that	directories  con
	      tain  2  fewer  subdirectories than their hard link
	      count.   This  option  is	 needed	 when	searching
	      filesystems  that do not follow the Unix directory-
	      link convention, such as CD-ROM or MS-DOS	 filesys
	      tems or AFS volume mount points.	Each directory on
	      a normal Unix filesystem has at least 2 hard links:
	      its  name	 and  its  `.'	entry.	Additionally, its
	      subdirectories (if any) each  have  a  `..'   entry
	      linked to that directory.	 When find is examining a
	      directory, after it has statted 2 fewer subdirecto
	      ries than the directory's link count, it knows that
	      the rest of the entries in the directory	are  non-
	      directories  (`leaf'  files in the directory tree).
	      If only the files' names need to be examined, there
	      is  no  need to stat them; this gives a significant
	      increase in search speed.

       -version, --version
	      Print the find version number and exit.

       -xdev  Don't descend directories on other filesystems.

4) 표현식-tests
   tests (N can be +N or -N or N):
       -amin N -anewer FILE -atime N -cmin N
       -cnewer FILE -ctime N -empty -false -fstype TYPE -gid N -group NAME
       -ilname PATTERN -iname PATTERN -inum N -ipath PATTERN -iregex PATTERN
       -links N -lname PATTERN -mmin N -mtime N -name PATTERN -newer FILE
       -nouser -nogroup -path PATTERN -perm [+-]MODE -regex PATTERN
       -size N[bckw] -true -type [bcdpfls] -uid N -used N -user NAME
       -xtype [bcdpfls]

       Numeric arguments can be specified as

       +n     for greater than n,

       -n     for less than n,

       n      for exactly n.

       -amin n
	      File was last accessed n minutes ago.

       -anewer file
	      File was last accessed more recently than file  was
	      modified.	  -anewer  is affected by -follow only if
	      -follow comes before -anewer on the command line.

       -atime n
	      File was last accessed n*24 hours ago.

       -cmin n
	      File's status was last changed n minutes ago.

       -cnewer file
	      File's status was last changed more  recently  than
	      file  was modified.  -cnewer is affected by -follow
	      only if -follow comes before -cnewer on the command
	      line.

       -ctime n
	      File's status was last changed n*24 hours ago.

       -empty File  is	empty  and  is either a regular file or a
	      directory.

       -false Always false.

       -fstype type
	      File is on a filesystem of type  type.   The  valid
	      filesystem  types	 vary among different versions of
	      Unix; an incomplete list of filesystem  types  that
	      are accepted on some version of Unix or another is:
	      ufs, 4.2, 4.3, nfs, tmp, mfs, S51K, S52K.	 You  can
	      use  -printf with the %F directive to see the types
	      of your filesystems.

       -gid n File's numeric group ID is n.

       -group gname
	      File belongs  to	group  gname  (numeric	group  ID
	      allowed).

       -ilname pattern
	      Like -lname, but the match is case insensitive.

       -iname pattern
	      Like -name, but the match is case insensitive.  For
	      example, the patterns `fo*'  and	`F??'  match  the
	      file names `Foo', `FOO', `foo', `fOo', etc.

       -inum n
	      File has inode number n.


       -perm mode
	      File's  permission  bits are exactly mode (octal or
	      symbolic).  Symbolic modes use mode 0 as a point of
	      departure.

       -perm -mode
	      All  of  the  permission	bits mode are set for the
	      file.

       -perm +mode
	      Any of the permission bits mode  are  set	 for  the
	      file.

       -regex pattern
	      File name matches regular expression pattern.  This
	      is a match on the whole path, not	 a  search.   For
	      example,	to match a file named `./fubar3', you can
	      use the regular expression  `.*bar.'  or	`.*b.*3',
	      but not `b.*r3'.

       -size n[bckw]
	      File uses n units of space.  The units are 512-byte
	      blocks by default or if `b' follows n, bytes if `c'
	      follows  n,  kilobytes  if `k' follows n, or 2-byte
	      words if `w' follows n.  The size	 does  not  count
	      indirect blocks, but it does count blocks in sparse
	      files that are not actually allocated.

       -true  Always true.

       -type c
	      File is of type c:

	      b	     block (buffered) special
	      c	     character (unbuffered) special
	      d	     directory
	      p	     named pipe (FIFO)
	      f	     regular file
	      l	     symbolic link
	      s	     socket

       -uid n File's numeric user ID is n.

       -used n
	      File was last accessed n days after its status  was
	      last changed.
       -user uname
	      File  is	owned  by  user	 uname	(numeric  user ID
	      allowed).

       -xtype c
	      The same as -type unless the  file  is  a	 symbolic
	      link.   For symbolic links: if -follow has not been
	      given, true if the file is a link to a file of type
	      c; if -follow has been given, true if c is `l'.  In
	      other words, for symbolic links, -xtype checks  the
	      type of the file that -type does not check.

5) 표현식-Actions
   actions:
       -exec COMMAND ; -fprint FILE -fprint0 FILE -fprintf FILE FORMAT
       -ok COMMAND ; -print -print0 -printf FORMAT -prune -ls

       -exec command ;
	      Execute command; true if 0 status is returned.  All
	      following arguments to find are taken to	be  argu
	      ments  to	 the command until an argument consisting
	      of `;' is encountered.  The string `{}' is replaced
	      by the current file name being processed everywhere
	      it occurs in the arguments to the command, not just
	      in arguments where it is alone, as in some versions
	      of find.	Both of these constructions might need to
	      be  escaped  (with a `\') or quoted to protect them
	      from expansion by the shell.  The command	 is  exe
	      cuted in the starting directory.

       -fls file
	      True; like -ls but write to file like -fprint.

       -fprint file
	      True;  print the full file name into file file.  If
	      file does not exist when find is run,  it	 is  cre
	      ated;  if it does exist, it is truncated.	 The file
	      names ``/dev/stdout'' and ``/dev/stderr'' are  han
	      dled  specially;	they refer to the standard output
	      and standard error output, respectively.

       -fprint0 file
	      True; like -print0 but write to file like	 -fprint.

       -fprintf file format
	      True;  like -printf but write to file like -fprint.

       -ok command ;
	      Like -exec but ask the user first (on the	 standard
	      input);  if the response does not start with `y' or
	      `Y', do not run the command, and return false.

       -print True; print the full file name on the standard out
	      put, followed by a newline.

       -print0
	      True; print the full file name on the standard out
	      put, followed by a  null	character.   This  allows
	      file  names  that	 contain newlines to be correctly
	      interpreted by programs that process the find  out
	      put.

       -printf format
	      True;  print  format on the standard output, inter
	      preting `\'  escapes  and	 `%'  directives.   Field
	      widths  and precisions can be specified as with the
	      `printf' C function.  Unlike -print,  -printf  does
	      not  add	a  newline at the end of the string.  The
	      escapes and directives are:

	      \a     Alarm bell.
	      \b     Backspace.
	      \c     Stop printing from this  format  immediately
		     and flush the output.
	      \f     Form feed.
	      \n     Newline.
	      \r     Carriage return.
	      \t     Horizontal tab.
	      \v     Vertical tab.
	      \\     A literal backslash (`\').

	      A	 `\' character followed by any other character is
	      treated as an ordinary character, so they both  are
	      printed.

	      %%     A literal percent sign.

	      %a     File's   last  access  time  in  the  format
		     returned by the C `ctime' function.

	      %Ak    File's last access time in the format speci
		     fied  by  k, which is either `@' or a direc
		     tive for the  C  `strftime'  function.   The
		     possible values for k are listed below; some
		     of them might not be available on	all  sys
		     tems,   due  to  differences  in  `strftime'
		     between systems.

		      @	     seconds since Jan.	 1,  1970,  00:00
			     GMT.

		     Time fields:

		      H	     hour (00..23)
		      I	     hour (01..12)
		      k	     hour ( 0..23)
		      l	     hour ( 1..12)
		      M	     minute (00..59)
		      p	     locale's AM or PM
		      r	     time, 12-hour (hh:mm:ss [AP]M)
		      S	     second (00..61)
		      T	     time, 24-hour (hh:mm:ss)
		      X	     locale's time representation (H:M:S)
		      Z	     time zone (e.g., EDT), or nothing if
			     no time zone is determinable

		     Date fields:

		      a	     locale's  abbreviated  weekday  name
			     (Sun..Sat)
		      A	     locale's full weekday name, variable
			     length (Sunday..Saturday)
		      b	     locale's	abbreviated   month  name
			     (Jan..Dec)
		      B	     locale's full month  name,	 variable
			     length (January..December)
		      c	     locale's  date  and time (Sat Nov 04
			     12:02:33 EST 1989)
		      d	     day of month (01..31)
		      D	     date (mm/dd/yy)
		      h	     same as b
		      j	     day of year (001..366)
		      m	     month (01..12)
		      U	     week number of year with  Sunday  as
			     first day of week (00..53)
		      w	     day of week (0..6)
		      W	     week  number  of year with Monday as
			     first day of week (00..53)
		      x	     locale's	  date	   representation
			     (mm/dd/yy)
		      y	     last two digits of year (00..99)
		      Y	     year (1970...)

	      %b     File's size in 512-byte blocks (rounded up).

	      %c     File's last status change time in the format
		     returned by the C `ctime' function.

	      %Ck    File's last status change time in the format
		     specified by k, which is the same as for %A.

	      %d     File's  depth in the directory tree; 0 means
		     the file is a command line argument.

	      %f     File's name  with	any  leading  directories
		     removed (only the last element).

	      %F     Type  of the filesystem the file is on; this
		     value can be used for -fstype.

	      %g     File's group name, or numeric  group  ID  if
		     the group has no name.

	      %G     File's numeric group ID.

	      %h     Leading  directories of file's name (all but
		     the last element).

	      %H     Command line argument under which	file  was
		     found.

	      %i     File's inode number (in decimal).

	      %k     File's size in 1K blocks (rounded up).

	      %l     Object  of	 symbolic  link	 (empty string if
		     file is not a symbolic link).

	      %m     File's permission bits (in octal).

	      %n     Number of hard links to file.

	      %p     File's name.

	      %P     File's name with the  name	 of  the  command
		     line  argument  under  which  it  was  found
		     removed.

	      %s     File's size in bytes.

	      %t     File's last modification time in the  format
		     returned by the C `ctime' function.

	      %Tk    File's  last modification time in the format
		     specified by k, which is the same as for %A.

	      %u     File's  user name, or numeric user ID if the
		     user has no name.

	      %U     File's numeric user ID.

	      A `%' character followed by any other character  is
	      discarded (but the other character is printed).

       -prune If  -depth  is  not given, true; do not descend the
	      current directory.
	      If -depth is given, false; no effect.

       -ls    True; list current file in  `ls  -dils'  format  on
	      standard	output.	  The  block  counts  are  of  1K
	      blocks,	 unless	   the	  environment	 variable
	      POSIXLY_CORRECT  is  set,	 in  which  case 512-byte
	      blocks are used.
 
출처 : http://www.linuxchannel.net/docs/find-xargs-ls.txt
 
추가
 
* find 명령어
사용형식: find [찾을 디렉토리경로] [찾기옵션] [찾은후 수행할 작업]
[찾을 디렉토리경로]
.   : 현재 디렉토리 이하를 검색대상으로 한다.
/   : 루트디렉토리(파일시스템전체)이하를 대상으로 한다.
~ID : 지정된ID의 홈대렉토리이하를 대상으로 한다.
[찾기옵션]
-empty  : 비어있는 파일을 찾는다.
-uid UID : 지정된 UID를 갖는 파일을 찾는다.
-gid GID : 지정된 GID를 갖는 파일을 찾는다.
-group 그룹명 : 지정된 group을 가진 파일을 찾는다.
-name  : 지정된 형식의 패턴을 가지는 파일을 찾는다.
-newer  : 지정된 파일 이후에 생성된 파일을 찾는다.
-perm  : 지정된 퍼미션을 가진 파일을 찾는다.
-used 일자수 : 최근 n일 이후에 변경된 파일을 찾는다.
-user  : 지정된 파일을 소유하고 있는 소유자의 모든 파일을 찾는다.
[찾은후 수행할 작업]
-exec "수행명령어" : 검색된 파일을 대상으로 "수행명령어"(쉘명령어)를 실행한다.
1. 특정 사용자의 ID소유로된 모든 파일 찾기
# find / -user test01 -print
2. 특정 사용자의 홈디렉토리 내에서  특정 파일 찾기
# find /home/test01 -name *.html -print
# find ~test01 -name *.html -print
3. 시스템내의 특정파일들을 검색하여 자동삭제하는 방법
# find ~test01 -name *.bak -exec rm -f {} \;
4. 지정한 소유자의 모든 파일을 찾아서 확인하기
# find / -user test01 -exec ls -l {} \;
5. 서버내의 불필요한 파일들 모두 정리(삭제)하기
# find / -name access_log -exec rm -f {} \;
6. 특정용량 이상되는 파일들 모두 찾기(용량단위로 파일검색)
# find /usr -size +10000k -exec ls -l {} \;
7. 특정 퍼미션을 가지고 있는 파일들 모두 찾기
# find / -perm 4755 -exec ls -l {} \;
8. 특정디렉토리내에 존재하는 모든 디렉토리 목록만 확인하기
# find ~test01 -type d -print
9. 서버내에 존재하는 모든 링크파일 검사하기
# find / -type l -exec ls -l {} \;
10. 쓰기 권한이 있는 파일 및 디렉토리 찾기
# find / -type f \( -perm -2 -o -perm -20 \) -exec ls -lg {} \;
# find / -type d \( -perm -2 -o -perm -20 \) -exec ls -ldg {} \;
11. 특정문자를 포함하는 파일찾기와 그 문자가 속한 행 찾기
# find ~test01 type f -exec egrep -i "doc" /dev/null {} \;

파일속 mms: 찾기찾기
find . -type f -name "webfile.html" -exec grep "mms://vod.xxxx.co.kr" {} /dev/null \;

파일 속 IP을 도메인으로 바꾸기
find . -type f -name "webfile.html" -exec perl -pi -e 's/211.xx.xx.39/vod.xxxx.co.kr/g' {} \;

특정 파일 속 IP 도메인으로 바꾸기
find . -type f -name "[0,1][0-9].html" -exec perl -pi -e 's/211.xx.xx.39/vod.xxxx.co.kr/g' {} \;

압축
for i in $(find . -name 'webfile.html'); do tar -rvf webfile.tgz $i; done

Posted by 샤키