GNU/Linux >> Linux Esercitazione >  >> Linux

Bash trova l'output dettagliato del comando

Soluzione 1:

Potresti inventare qualcosa con -printf , ma il più semplice è semplicemente aggiungere -print sulla fine. Questo mostrerà ciò che è stato eliminato con successo.

Soluzione 2:

Che ne dici di usare solo rm -vf per l'output rm dettagliato.

$ touch file1 file2 file3
$ find . -name "file?" -exec rm -vf {} \;
removed `./file2'
removed `./file3'
removed `./file1'

Soluzione 3:

Un'alternativa è lasciare che i comandi vengano eseguiti da sh -x :

$ find . -type f -print0 | xargs -0 -n1 echo rm | sh -x
+ rm ./file1
+ rm ./file2
+ rm ./file3

Soluzione 4:

C'è anche find -D xxxx che potrebbe aiutare in alcuni casi.

 $ 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

Di seguito sono riportati due esempi di find -D search :

Utilizzando 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 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)

Linux
  1. trova:comando non trovato

  2. Visualizzazione dell'output completo del comando PS

  3. Il reindirizzamento dell'output del comando a una variabile in bash non riesce

  4. Output del comando Linux come parametro di un altro comando

  5. Esegui il comando bash sulla pipeline jenkins

Bash:Scrivi su file

Bash Heredoc

Comando sorgente Bash

Comando della cronologia in Linux (Cronologia di Bash)

Comando Bash printf

Script Bash(II)