一、命令方法

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

最新文章

  1. cpp 4个类型转换
  2. MYSQL分页存储过程及事务处理
  3. JS 基本语句
  4. 团队项目作业第二项:利用NABCD模型进行竞争性需求分析
  5. apue第四章学习总结
  6. JQuery validate 在IE兼容模式下出现 js错误(成员找不到)的修正:
  7. C# try catch finally 执行
  8. web前端:html
  9. SUSE Linux 下redis 的坑
  10. 前端实现搜索历史和清空历史(angularjs+ionic)
  11. 017-封装-OC笔记
  12. [Swift]LeetCode721. 账户合并 | Accounts Merge
  13. MYSQL ini 配置文件详解及性能优化方案
  14. scrapy之Crawspider 腾讯招聘实战案例
  15. m3u8转码
  16. COM口总是有惊叹号怎么办
  17. c#构造函数对string类型赋初值
  18. Redis注意事项
  19. c字符输出
  20. win7上安装theano keras深度学习框架

热门文章

  1. java对象,引用的区别
  2. 4.9 Routing -- Query Parameters
  3. 《大话设计模式》ruby版代码:建造者模式
  4. ac自动机系列
  5. Mkdocs 搭建
  6. iOS开发之开发者申请
  7. web上的复制
  8. nodejs 8 利用原生 util.promisify() 实现 promise.delay()
  9. 如何为openwrt生成补丁
  10. Flask 4 拓展