有没有办法告诉bash find
命令输出它在做什么(详细模式)?
例如命令: find /media/1Tb/videos -maxdepth 1 -type d -mtime +7 -exec rm -rf {} \;
输出:
Found /media/1Tb/videos/102, executing rm -rf /media/1Tb/videos/102 ...
你可以用-printf
来制作一些东西,但是最简单的就是在最后加上-print
。 这将显示已成功删除的内容。
如何使用rm -vf
输出冗长的rm。
$ touch file1 file2 file3 $ find . -name "file?" -exec rm -vf {} \; removed `./file2' removed `./file3' removed `./file1'
另一种方法是让这些命令由sh -x
来执行:
$ find . -type f -print0 | xargs -0 -n1 echo rm | sh -x + rm ./file1 + rm ./file2 + rm ./file3
还有一些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)