Você pode inventar algo com -printf , mas o mais fácil é apenas colocar -print no final. Isso mostrará o que foi excluído com sucesso.
Existe uma maneira de dizer ao comando bash find para gerar o que está fazendo (modo detalhado)?
Por exemplo, para o comando:
find /media/1Tb/videos -maxdepth 1 -type d -mtime +7 -exec rm -rf {} \; para a saída:
Found /media/1Tb/videos/102, executing rm -rf /media/1Tb/videos/102
...
Que tal usar apenas rm -vf para a saída verbose rm?
$ touch file1 file2 file3
$ find . -name "file?" -exec rm -vf {} \;
removed './file2'
removed './file3'
removed './file1'
Uma alternativa é permitir que os comandos sejam executados por sh -x :
$ find . -type f -print0 | xargs -0 -n1 echo rm | sh -x
+ rm ./file1
+ rm ./file2
+ rm ./file3
Há também find -D xxxx que pode ajudar em alguns casos.
$ 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
Abaixo estão dois exemplos de find -D search :
Usando o 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)
Usando o 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)
A resposta do hlovdav foi suficiente para mim, mas fiz algumas modificações para meu próprio uso
find . -name 'application*.yml' -print0 | xargs -0 -I %% bash -c 'rm -v "$1"' -- "%%"
Explicação
pattern null separado, importante se você tiver nomes de arquivo com espaços ou caracteres incomuns nele xargs read null separated, defina cada alocador de espaço de registro como %%
Isso também garante que toda vez que ele usa apenas um argumento bash , one-liner, qualquer coisa que esteja dentro, deve estar entre aspas simples '
-- significa que qualquer coisa que eu faça depois disso não é xargs ou bash opções, mas parâmetros posicionais para meu script de uma linha bash , você pode acessar %% como $1 , argumento posicional No # 1 Observação: você pode alterar %% com qualquer coisa, apenas certifique-se de não precisar usá-la para nada além de um espaço reservado. Usar o dólar $ ou @ pode não ser bom, a menos que seja o dobro @ como @@ .