怎样cp文件夹时忽略指定的文件夹和文件
在备份ltedecoder程序时,须要把此文件夹拷由到bak文件夹下。但decoder文件夹下有个大文件,不须要备份,还有日志问题,也不须要备份,怎样实现呢??
方法:
cd /source-dir
find . -name .snapshot-prune-o-print0 | cpio -pmd0 /dest-dir
解释: This command copies the contents of /source-dir to /dest-dir, but omits files and directories named .snapshot (and anything in them). The construct-prune -o -print0
is quite common. The idea here is that the expression before -prune matches things which are to be pruned. However, the -prune action itself returns true, so the following -o ensures that the right hand side is evaluated only for those directories
which didn't get pruned (the contents of the pruned directories are not even visited, so their contents are irrelevant). The expression on the right hand side of the -o is in parentheses only for clarity. It emphasises that the -print0 action takes place
only for things that didn't have -prune applied to them. Because the default `and' condition between tests binds more tightly than -o, this is the default anyway, but the parentheses help to show what is going on.
此段的意思是:当找到name为.snapshot时,prune就会返回真。-o是或的意思,“或”的使用技巧是当左边的表达式为“真”时。则不会运算右边的表达式。当左边的表达式为假。则运算右边的表达式,即,当左边name不为.snapshot。则进行右边的表达式,右边的表达式意思是print文件名称(包含路径的);当找到name为.snapshot时,则不打印文件名称。这样就实现了把非.snampshot为命名的文件打印出来并交给cpio进行处理。cpio则把这些文件拷则的dest-dir中,实现忽略.snampshot文件的拷备(注:文件指目录或file名)。
拓展:
-prune -o ... -print0
“... -print0”
这里能够使用find的查找文件的參数。如-name,-size等。
find . -name Persistence -prune -o ! -name '*log*' ! -size +100M -print0 | cpio -pmd0 /root/do_bak/ltedecoder
上面则不仅忽略Persistence文件夹,还会忽略包涵log的文件或文件夹,还会忽略大于100M的文件。
注意: 你一定注意到了find 后面是“.”,代表当前文件夹,即此命令必须是pwd是你要拷则的文件夹里面,如你把sour-dir的文件进行拷则,则须要先cd $sour-dir。
最新文章
- 【Windows编程】系列第九篇:剪贴板使用
- ubuntu14.04为安装fcitx卸载ibus后出现system setting (系统设置)中图标消失的问题
- 全球第一本基于Bootstrap V3.x的图书《深入理解Bootstrap》终于上市了,再次免费送书15本【活动结束】
- eNSP的使用
- 一种透明效果的view
- 数往知来JavaScript_DOM<;十>;
- Java log code example
- Java基础知识强化之集合框架笔记66:Map集合面试题之HashMap和Hashtable区别(重要)
- TOP命令解析
- vs2012 发布网站丢失文件
- (4)事件处理——(3)代码执行的顺序(Timing of code execution)
- 程序员面试必备-链表各种操作及其实现方法(c实现)
- Linux查看用于终止进程命令
- Pat1128:N Queens Puzzle
- 使用QuertZ组件来搞项目工作流(一)
- Oracle12c 从入门到精通(第二版) 闫红岩 金松河 编著
- windows 下安装 docker
- php使用 utf8_encode 来将特殊字符转成 utf8
- Unity动态创建FBX模型配置文件的存放路径
- 使用 ASMCMD 工具管理ASM目录及文件