将通过find命令找到的文件拷贝到一个新的目录中
有这样的一个需求,需要将一部分符合条件的文件从一个目录拷贝到另一个目录中,我通过find命令从源目录查找到符合条件的文件然后使用cp命令拷贝到目标目录:
方法一
命令如下:
find src_dir -name "access.log.2011102[2-6]*" -exec cp {} dst_dir \;
拷贝文件到远程主机上的目标目录的命令:
find src_dir -name "access.log.2011102[2-6]*" -exec scp {} 用户名@主机ip:dst_dir \;
方法二
find src_dir -name "access.log.2011102[2-6]*" |xargs -i cp {} dst_dir
或
find src_dir -name "access.log.2011102[2-6]*" |xargs -I {} cp {} dst_dir
拷贝文件到远程主机上的目标目录的命令:
find src_dir -name "access.log.2011102[2-6]*" |xargs -i scp {} 用户名@主机ip:dst_dir
或
find src_dir -name "access.log.2011102[2-6]*" |xargs -I {} scp {} 用户名@主机ip:dst_dir
src_dir 源目录
dst_dir 目标目录
access.log.2011102[2-6]* 文件名的正则表达式,获取文件的条件
方法三
find命令结合cp命令,拷贝某个目录下所有文件到另一个目录中
要求整个目录完全拷贝到另一个目录,并且忽略个别目录,脚本如下:
find ./ -path '/tmp/mnt/disk1/ignore' -prune -o \( -name '*' ! -name "*.tmp" \) | xargs cp "目的目录" "{}" \;
在上面这个脚本中,当执行到“| xargs cp”时,假设输入的字符串类似如下:
/tmp/mnt/disk1/tt.txt
/tmp/mnt/disk1/test/dd.txt
要求执行“xargs cp”后,相应拷贝成如下的目录结构
(即:原来disk1目录下所有文件都拷贝到src目录下,目录结构不变):
/tmp/mnt/src/tt.txt
/tmp/mnt/src/test/dd.txt
详细解决方案
将通过find命令找到的文件拷贝到一个新的目录中
热度:48 发布时间:2024-01-25 00:08:26.0
相关解决方案
- Could not find a getter for name in class解决方法
- 用eclipse打包jar后运行,弹出异常could not find main class
- 有人用过zeroMQ吗?一直揭示C:\Program Files\Java\jre6\bin\jzmq.dll: Can't find dependent li
- Selection.Find 选择所有匹配结果解决办法
- word vba find 怎么匹配0个或多个前面的字符
- 求大神帮忙,汇编开展连接时出现fatal error cannot find msvcrt.lib文件
- Find and retrieve resources by VTMOS例子出有关问题
- vfp dll .cannot find entry point解决办法
- windows下安装DB2出现error opening db2 setup launchpad cannot find supported wen brows解决思路
- cgi+boa,cgi页面施行失败。提示cgi_header: unable to find LFLF
- unable to find package import : dclusr.bpi
- It's difficult to find a good job!解决方案
- 每天背熟一句英语(25)I've searched far and wide for the book but I still can't find it.解决方法
- 急linux 上代码编译出现/usr/bin/ld: cannot find -lsicui18n
- 为arm平台写了个使用sdl的测试程序衔接时出现skipping incompatible然后就提示cannot find -lSDL了,该如何解决
- 这道题关于check log shipping and find out the problem,该如何处理
- jquery 里边的.find() .each() .parent() .value(parseInt())
- 错误信息:could not find the main class programe will exit
- Cannot find FacesContext这个是什么错
- [求助] c编译时为什么总是出现“link error: unable to find input file ' ...
- [求助] c编译时为什么总是出现“link error: unable to find input file ' ...
- [求助] c编译时为什么总是出现“link error: unable to find input file ' ...
- [求助] c编译时为什么总是出现“link error: unable to find input file ' ...
- find 取舍input或者select用逗号
- hibernate org.apache.jasper.JasperException: could not find file: hibernate.cfg
- PHP Simple HTML DOM Parser 的 find() 函数没法找到元素的类属性
- 异常:Cannot find bean under name org.apache.struts.taglib.html.BEAN
- Struts标签之Cannot find bean under name org.apache.struts.taglib.html.BEAN异常
- 请问sublime text ctags安装后can't find class(ctags生成出错)
- 编译php报错:/usr/bin/ld: cannot find -liconv解决办法