답변:
와 함께 무언가를 만들 수는 -printf
있지만 가장 쉬운 방법은 -print
끝 부분에 고정하는 것 입니다. 성공적으로 삭제 된 내용이 표시됩니다.
find
사랑은 또 다른 조금 성장했습니다. thanks :)
find -L . -type l -delete -print
또한이 find -D xxxx
경우에 도움이 될 수있다.
$ find -D help
Valid arguments for -D:
help Explain the various -D options
tree Display the expression tree
search Navigate the directory tree verbosely
stat Trace calls to stat(2) and lstat(2)
rates Indicate how often each predicate succeeded
opt Show diagnostic information relating to optimisation
exec Show diagnostic information relating to -exec, -execdir, -ok and -okdir
다음은 두 가지 예입니다 find -D search
.
RHEL 6.3 ( find
v4.4) 사용 :
$ mkdir -p aa/bb
$ touch aa/11 aa/22 aa/33 aa/bb/44 aa/bb/55
$ find -D search aa -type f -delete
consider_visiting: fts_info=FTS_D , fts_level= 0, prev_depth=-2147483648 fts_path=`aa', fts_accpath=`aa'
consider_visiting: fts_info=FTS_D , fts_level= 1, prev_depth=0 fts_path=`aa/bb', fts_accpath=`bb'
consider_visiting: fts_info=FTS_NSOK, fts_level= 2, prev_depth=1 fts_path=`aa/bb/55', fts_accpath=`55'
consider_visiting: fts_info=FTS_NSOK, fts_level= 2, prev_depth=2 fts_path=`aa/bb/44', fts_accpath=`44'
consider_visiting: fts_info=FTS_DP, fts_level= 1, prev_depth=2 fts_path=`aa/bb', fts_accpath=`bb'
consider_visiting: fts_info=FTS_NSOK, fts_level= 1, prev_depth=1 fts_path=`aa/22', fts_accpath=`22'
consider_visiting: fts_info=FTS_NSOK, fts_level= 1, prev_depth=1 fts_path=`aa/33', fts_accpath=`33'
consider_visiting: fts_info=FTS_NSOK, fts_level= 1, prev_depth=1 fts_path=`aa/11', fts_accpath=`11'
consider_visiting: fts_info=FTS_DP, fts_level= 0, prev_depth=1 fts_path=`aa', fts_accpath=`aa'
$ find --version
find (GNU findutils) 4.4.2
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Eric B. Decker, James Youngman, and Kevin Dalley.
Built using GNU gnulib version e5573b1bad88bfabcda181b9e0125fb0c52b7d3b
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION SELINUX FTS() CBO(level=0)
Cygwin 1.7 ( find
4.5) 사용 :
$ mkdir -p aa/bb
$ touch aa/11 aa/22 aa/33 aa/bb/44 aa/bb/55
$ find -D search aa -type f -delete
consider_visiting (early): 'aa': fts_info=FTS_D , fts_level= 0, prev_depth=-2147483648 fts_path='aa', fts_accpath='aa'
consider_visiting (late): 'aa': fts_info=FTS_D , isdir=1 ignore=1 have_stat=1 have_type=1
consider_visiting (early): 'aa/11': fts_info=FTS_NSOK, fts_level= 1, prev_depth=0 fts_path='aa/11', fts_accpath='11'
consider_visiting (late): 'aa/11': fts_info=FTS_NSOK, isdir=0 ignore=0 have_stat=0 have_type=1
consider_visiting (early): 'aa/22': fts_info=FTS_NSOK, fts_level= 1, prev_depth=1 fts_path='aa/22', fts_accpath='22'
consider_visiting (late): 'aa/22': fts_info=FTS_NSOK, isdir=0 ignore=0 have_stat=0 have_type=1
consider_visiting (early): 'aa/33': fts_info=FTS_NSOK, fts_level= 1, prev_depth=1 fts_path='aa/33', fts_accpath='33'
consider_visiting (late): 'aa/33': fts_info=FTS_NSOK, isdir=0 ignore=0 have_stat=0 have_type=1
consider_visiting (early): 'aa/bb': fts_info=FTS_D , fts_level= 1, prev_depth=1 fts_path='aa/bb', fts_accpath='bb'
consider_visiting (late): 'aa/bb': fts_info=FTS_D , isdir=1 ignore=1 have_stat=1 have_type=1
consider_visiting (early): 'aa/bb/44': fts_info=FTS_NSOK, fts_level= 2, prev_depth=1 fts_path='aa/bb/44', fts_accpath='44'
consider_visiting (late): 'aa/bb/44': fts_info=FTS_NSOK, isdir=0 ignore=0 have_stat=0 have_type=1
consider_visiting (early): 'aa/bb/55': fts_info=FTS_NSOK, fts_level= 2, prev_depth=2 fts_path='aa/bb/55', fts_accpath='55'
consider_visiting (late): 'aa/bb/55': fts_info=FTS_NSOK, isdir=0 ignore=0 have_stat=0 have_type=1
consider_visiting (early): 'aa/bb': fts_info=FTS_DP, fts_level= 1, prev_depth=2 fts_path='aa/bb', fts_accpath='bb'
consider_visiting (late): 'aa/bb': fts_info=FTS_DP, isdir=1 ignore=0 have_stat=1 have_type=1
consider_visiting (early): 'aa': fts_info=FTS_DP, fts_level= 0, prev_depth=1 fts_path='aa', fts_accpath='aa'
consider_visiting (late): 'aa': fts_info=FTS_DP, isdir=1 ignore=0 have_stat=1 have_type=1
$ find --version
find (GNU findutils) 4.5.11
Packaged by Cygwin (4.5.11-1)
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Eric B. Decker, James Youngman, and Kevin Dalley.
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS(FTS_CWDFD) CBO(level=2)
@ hlovdav의 대답 은 충분했지만 내 용도에 맞게 수정했습니다.
find . -name 'application*.yml' -print0 | xargs -0 -I %% bash -c 'rm -v "$1"' -- "%%"
설명
pattern
null
공백이 있거나 이상한 문자가 포함 된 파일 이름이있는 경우 중요하게 구분되어 인쇄 하십시오.xargs
null
분리 된 읽기 , 각 레코드 플레이스 홀더를 %%
다음으로 설정하십시오. 또한 하나의 인수 만 사용할 때마다 보장합니다.bash
명령, 하나의 라이너, 모든 것이 들어갑니다. 작은 따옴표로 묶어야합니다. '
--
이것은 내가 한 옵션 xargs
또는 bash
옵션이 아니라 하나의 라이너 스크립트에 대한 위치 매개 변수입니다.bash
스크립트 내 에서 위치 인수 No # 1 %%
로 액세스 할 수 있습니다$1
참고 : %%
자리 표시 자 이외의 다른 용도로 사용할 필요가없는 것으로 변경하면됩니다. 달러를 사용 $
하거나 @
이 두 배 않는 한, 잘되지 않을 수도 있습니다 @
처럼 @@
.
find
엄지 손가락