linux 删除指定文件以外的文件

使用find 排除 

找到./tools/dbsetup/startlibs/config/suconfig/ 下除了以下文件名的文件

find ./tools/dbsetup/startlibs/config/suconfig/ ! -name 'su_aa.json' \
! -name 'su_aip.json' \
! -name 'su_bc.json'  \
! -name 'su_design.json'  \
! -name 'su_df.json' \
! -name 'su_df_view.json'   \
! -name 'su_gl.json'  \
! -name 'su_sys.json' 

2 加-exec调用删除

find ./tools/dbsetup/startlibs/config/suconfig/ ! -name 'su_aa.json' \
! -name 'su_aip.json' \
! -name 'su_bc.json'  \
! -name 'su_design.json'  \
! -name 'su_df.json' \
! -name 'su_df_view.json'   \
! -name 'su_gl.json'  \
! -name 'su_sys.json' -exec rm -f {} +

{} 标识find命令找到的文件

结束符有两种   ; 和 +

;会对每个找到item执行command

+ 会执行一次

-exec rm -f {} +   执行 rm -f 1 2 3 等同于
-exec rm -f {} \; 执行 rm -f 1 \ rm -f 2 \ rm -f 3
\的作用是防止截断

猜你喜欢

转载自www.cnblogs.com/wolbo/p/12448024.html