怎样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。

时间: 2024-07-30 06:01:55

怎样cp文件夹时忽略指定的文件夹和文件的相关文章

如何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 dir

git提交时忽略指定文件

git提交时忽略指定文件 我们在项目开发过程中经常用到git来管理自己的项目,使用git版本控制进行多人协作开发具有许多优势,这里就不一一阐述了,有兴趣的同学可以自己去查找资料进行系统的学习.而本篇文章要说的是git使用过程中会遇到的一个问题,就是我们在项目开发过程中经常会修改一些配置文件 ,但是有的时候这些配置文件不需要被提交到远程仓库中,只在本地生效即可,此时就需要我们每次提交代码时把该文件给手动忽略,那么可不可以把该文件设置成永久忽略呢?答案肯定是有的,git的gitignore文件中可以

node-webkit中保存文件图片时如何指定保存类型

node-webkit中保存文件图片时如何指定保存类型,nw中可以用html的属性donwload属性来下载,最简单但它弹出的下载框可以重命名时把后缀去掉,用户不小心会把文件或图片后缀去掉,导致打不开文件.另外可以用input 的accept属性打开一个<input style="display:none;" id="saveImg" type="file" nwsaveas="imge.png"  accept=&qu

expect脚本同步文件、expect脚本指定host和同步的文件、构建文件分发系统、批量远程执行命

expect脚本当中去把一台机器的文件同步到另外一台机器上去,自动同步文件 [[email protected] sbin]# vim 4.expect ##编辑脚本 写入一下内容: #!/usr/bin/expect set passwd "hanshuo" spawn rsync -av [email protected]:/tmp/12.txt /tmp/ expect { "yes/no" { send "yes\r"} "pa

idea使用Git提交代码时忽略指定文件或文件夹

简述 使用idea编写代码并使用git作为版本控制器的时候,常常不需要提交配置文件以及一些其他不需要提交的文件,可以使用.ignore插件来在上传的时候忽略一些文件或文件夹. 安装 注意:安装完成之后要重启(restart)IDEA,插件才会生效. 配置   生成文件内容解释: 内容就是“禁止”提交更新的文件夹名称或文件类型.每个文件夹占一行. 补充: 禁止提交的文件夹在服务器(也就是GitHub)上面不能存在,如果存在的话你要先删除才可以.  禁止提交更新的文件或文件夹在项目目录中是灰色的.

TortoiseSVN 更新时忽略指定文件夹

命令行可以这么来svn update –set-depth=exclude 文件夹 那么TortoiseSVN客户端呢?在文件夹右键中的”更新至版本(U)”更新深度选”排除”,确定,搞定下次更新就不会再更新此目录要恢复的话在上级目录做相同操作,只是更新深度选择”全递归” TortoiseSVN 1.6以上支持

统计指定目录下所有mp4文件的时长(包含子目录下的文件)

1 # -*- coding:utf-8 -*- 2 # Author :Zcb 3 4 import os 5 from moviepy.editor import VideoFileClip 6 7 file_Dir = u"e:\\test" #加个u 是表示unicode 一般用在中文字符前 8 sum_time =0 9 10 class FileCheck(): 11 def __init__(self): 12 self.file_dir = file_Dir 13 14

spl处理文件(文件详细信息、文件遍历、查询指定行、写入CSV文件)

<?php /** * 文件操作 */ //常用操作 $file = new SplFileInfo('D:/workspace/xlyy/spl/test.txt'); $file_info = array( 'getATime' => $file->getATime(), //最后访问时间 'getBasename' => $file->getBasename(), //获取文件名 'getCTime' => $file->getCTime(), //获取in

Sublime Text 查找时排除指定的文件夹或文件

Sublime Text 查找时排除指定的文件夹或文件 Ctrl + Shift + F 这组快捷键可以调出 Sublime Text 的查找替换窗口,里边有一栏 Where,可以做一些高级设置: d:\dir\ , -*.css, -/*debug/* , -*.cache D:\Projects\ 表示在该目录下寻找,也可以写多个目录 *.cs 表示找 cs 后缀的文件,也可以写多个后缀 -/*Debug/* 表示排除 Debug 文件夹内的所有文件 -*.cache 表示排除 cache