1. 删除
test文件夹中含有两个文件,需要把文件删除,不删除文件夹
-r 就是向下递归,不管有多少级目录,一并删除
-f 就是直接强行删除,不作任何提示的意思

1.1 删除失败
- rm -rf /home/xiaoyu/yu/test/
- rm -rf /home/xiaoyu/yu/test
全部把文件也删除啦
1.1 删除成功 - rm -rf /home/xiaoyu/yu/test/*
2. 复制
把文件夹1中的数据复制到文件夹2中,如果有重名的会重复覆盖。


复制并覆盖
# coding:utf-8
import subprocess
# 使用程序运行xshell命令测试移动复制数据
def codeRunXshellCommandToCopy(path1, path2):
print('使用程序运行xshell命令测试移动复制数据')
subprocess.call("cp -r " + path1 + ' ' + path2, shell=True)
if __name__ == '__main__':
path1 = '/py_move_file/file1/*.txt'
path2 = '/py_move_file/file2'
codeRunXshellCommandToCopy(path1, path2)
复制完成后,会把文件夹1中的数据全部粘贴到文件2夹中,如果文件夹2和文件夹1有相同文件,会替换文件夹2中的文件。
网友评论