Linux下同时复制多个文件
方法一
- 使用cp命令
cp /home/usr/dir/{file1,file2,file3,file4} /home/usr/destination/
需要注意的是这几个文件之间不要有空格
- 具有共同前缀
cp /home/usr/dir/file{1..4} ./
复制的文件是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 中定义要复制的文件名字,只要给出名字即可,不需要路径
Linux下同时复制多个文件的更多相关文章
- 【转】Linux下同时复制多个文件
一.命令方法 1.使用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 用户主目录的基点,比 ...
随机推荐
- iOS-UISearchBar去掉边线
解决办法: UISearchBar 去除边线 属性search.searchBarStyle = minimal 即可
- MySQL主从不一致修复
场景: 线上正在服务的库由于紧急主从切换导致主从不一致,报错信息如下: Last_Error: Coordinator stopped because there were error(s) in t ...
- 修改docker时区
在实际业务场景中,经常碰到启动了一个容器,容器的时区是UTC的导致还需要重新运行: 我们在具体处理时也出现了该显现 业务场景: 数据库系统定时备份脚本, 定时备份脚本按照每天备份, 通过k8s启动容器 ...
- Oracle-Rman(物理备份)
Rman(物理备份) Rman -recover manager Rman 备份的对象 数据文件 数据文件 (Data File) 控制文件 控制文件 (Control File) 参数文件 参数文件 ...
- php 字母和数字验证码
//验证码 <?php //实现简单的验证码 //session_start session_start(); //画布 $image = imagecreatetruecolor(100, 3 ...
- telnet --- no route to host solution "iptables -F " in the target machine
telnet --- no route to host solution "iptables -F " in the target machine
- tomcat和jboss的区别
1. Tomcat是Apache鼎力支持的Java Web应用服务器(注:servlet容器),由于它优秀的稳定性以及丰富的文档资料,广泛的使用人群,从而在开源领域受到最广泛的青睐. 2. Jboss ...
- Leetcode 之 Set Mismatch
645. Set Mismatch 1.Problem The set S originally contains numbers from 1 to n. But unfortunately, du ...
- WEB安全验收参考文档——From Github
文章https://xianzhi.aliyun.com/forum/read/793.html 里面涉及到了web安全验收参考文档: 其实github上老外对此也做过一些整理.详情参考:https: ...
- 如何做好部门以及公司的文档管理、知识管理以及情报管理?——By Me
之前针对部门的文档管理开发平台进行过一次需求调研分析,对于实现方案与我们的实际需求之前的满足情况系统梳理了一下,我觉得对于有类似需求的团队或者公司应该有可以借鉴的地方,发到这里供大家参考.如有不正之处 ...