【转】Linux下同时复制多个文件
一、命令方法
1.使用cp命令
cp /home/usr/dir/{file1,file2,file3,file4} /home/usr/destination/
需要注意的是这几个文件之间不要有空格
2.具有共同前缀
cp /home/usr/dir/file{..} ./
复制的文件是file1, file2, file3, file4
二、脚本方法
使用python脚本 shutil库
import os,sys,shutil
### copies a list of files from source. handles duplicates.
def rename(file_name, dst, num=1):
#splits file name to add number distinction
(file_prefix, exstension) = os.path.splitext(file_name)
renamed = "%s(%d)%s" % (file_prefix,num,exstension) #checks if renamed file exists. Renames file if it does exist.
if os.path.exists(dst + renamed):
return rename(file_name, dst, num + 1)
else:
return renamed def copy_files(src,dst,file_list):
for files in file_list:
src_file_path = src + files
dst_file_path = dst + files
if os.path.exists(dst_file_path):
new_file_name = rename(files, dst)
dst_file_path = dst + new_file_name print "Copying: " + dst_file_path
try:
# 复制操作主要就是这句
shutil.copyfile(src_file_path,dst_file_path)
except IOError:
print src_file_path + " does not exist"
raw_input("Please, press enter to continue.") def read_file(file_name):
f = open(file_name)
#reads each line of file (f), strips out extra whitespace and
#returns list with each line of the file being an element of the list
content = [x.strip() for x in f.readlines()]
f.close()
return content src = sys.argv[1]
dst = sys.argv[2]
file_with_list = sys.argv[3] copy_files(src,dst,read_file(file_with_list))
2. 将以上代码保存为move.py
3. 运行 $ python move.py /path/to/src/ /path/to/dst/ file.txt
4. file.txt 中定义要复制的文件名字,只要给出名字即可,不需要路径
转自:https://www.cnblogs.com/zhonghuasong/p/7352758.html
【转】Linux下同时复制多个文件的更多相关文章
- Linux下同时复制多个文件
方法一 使用cp命令 cp /home/usr/dir/{file1,file2,file3,file4} /home/usr/destination/ 需要注意的是这几个文件之间不要有空格 具有共同 ...
- linux下怎么样上传下载文件夹
Linux下目录复制:本机->远程服务器 scp -r /home/shaoxiaohu/test1 zhidao@192.168.0.1:/home/test2 test1为源目录,test2 ...
- linux下,如何把整个文件夹上传到服务器(另一台linux)
1.Linux下目录复制:本机->远程服务器 scp -r /home/shaoxiaohu/test1 zhidao@192.168.0.1:/home/test2 #test1为源目录, ...
- linux 下C语言编程库文件处理与Makefile编写
做开发快3年了,在linux下编译安装软件算是家常便饭了.就拿gcc来说,都有不下10次了,可基本每次都会碰到些奇奇怪怪的问题.看来还是像vs.codeblocks这样的ide把人弄蠢了.便下定决心一 ...
- Linux下用rm删除的文件的恢复方法
Linux下用rm删除的文件的恢复方法_Linux教程_Linux公社-Linux系统门户网站https://www.linuxidc.com/Linux/2008-08/14744.htm linu ...
- linux下查找指定后缀的文件
1.linux下查找指定后缀的文件 例如查找当前目录下的所有后缀名时.c或.h的文件 find . -type f -regex ".*\.\(c\|h\)"
- 【转】linux下,如何把整个文件夹上传到服务器(另一台linux)
原文转自:https://zhidao.baidu.com/question/1046040541327493019.html 1.Linux下目录复制:本机->远程服务器 scp -r /h ...
- Linux下自动清除MySQL日志文件
MySQL运行过程中会生成大量的日志文件,占用不少空间,修改my.cnf文件配置bin-log过期时间,在Linux下自动清除MySQL日志文件 [mysqld] expire-logs-days= ...
- Linux下的文件结构,及对应文件夹的作用
Linux下的文件结构,及对应文件夹的作用 /bin 二进制可执行命令 /dev 设备特殊文件 /etc 系统管理和配置文件 /etc/rc.d 启动的配置文件和脚本 /home 用户主目录的基点,比 ...
随机推荐
- 【开发者笔记】MQTT python测试笔记
MQTT是基于订阅/发布的物联网协议. python测试需要一个发送进程和接收进程,即一个发送客户端和一个接收客户端,如果这两个客户端工作在同一个topic下,那么就能进行消息互通了. 服务器用“io ...
- Winform 下使用WebBrowser的HTML编辑控件—WinHtmlControl 在win7 IE9下的问题
问题是这样的,有一个需要用到富文本的地方,由于是winform的程序,而且程序是上一代老员工留下的,错误百出,现在要尽量修复,至少保证能正常使用,于是就开始一点点问题修复. 在win7 64位系统下出 ...
- glog安装与使用
window环境下glog的安装 载后解压,利用Visual Studio打开google-glog.sln.生成解决方案 打开sln会有几个项目,libglog是动态库,生成dll,libglog_ ...
- 3.9 Templates -- Input Helpers
一.Input Helpers Ember中{{input}}和{{textarea}}是创建常规表单控件最简单的方法. {{input}}包裹内建的Ember.TextField和Ember.Che ...
- 3.12 Templates -- Wrting Helpers(编写辅助器)
一.概述 1. Helpers允许你向你的模板添加超出在Ember中开箱即用的额外的功能.辅助器是最有用的,用于将来自模型和组件的原始值转换成更适合于用户的格式. 2. 例如,假设我们有一个Invoi ...
- 限制可编辑div只能输入纯文本
本博客转载自张鑫旭大神的一篇文章:小tip: 如何让contenteditable元素只能输入纯文本,原文地址:http://www.zhangxinxu.com/wordpress/2016/01/ ...
- 文件上传—SSH框架文件上传
1.准备上传的api组件 <dependency> <groupId>commons-io</groupId> <artifactId>commons- ...
- LFD,非官方的Windows二进制文件的Python扩展包
LFD,非官方的Windows二进制文件的Python扩展包 LFD,非官方版本.32和64位.Windows.二进制文件.科学开源.Python扩展包 克里斯托夫·戈尔克(by Christoph ...
- docker 容器目录挂载 | 进出容器
docker run --name wnginx -d -p 9001:80 -v /home/www:/usr/share/nginx/html nginx --name 别名 -d ...
- shell给tcp或udp服务发送16进制报文指令
指令:(sleep 2;echo "000F737D61747573" | xxd -r -p ;sleep 1)|nc 192.168.137.1 15000|hexdump - ...