首页 > 代码库 > Linux 回收站
Linux 回收站
一个小功能,起因是禁止用户使用rm
#!/usr/local/bin/python3 # coding:utf-8 # Create your views here. # ==================================================== # Author: chang - EMail:changbo@hmg100.com # Last modified: 2017-06-20 # Filename: linuxsafe.py # Description: linux safe js, base # blog:http://www.cnblogs.com/changbo # ==================================================== """ 1,初始化用户环境alias rm=‘mv --verbose -f --backup=numbered --target-directory /tmp/trash‘ """ import os import shutil import subprocess def trash(): if not os.path.exists(‘/tmp/trash‘): os.mkdir(‘/tmp/trash‘) os.chmod(‘/tmp/trash‘, 3) else: shutil.rmtree(‘/tmp/trash‘) os.mkdir(‘/tmp/trash‘) os.chmod(‘/tmp/trash‘, 3) if __name__ == ‘__main__‘: commond1 = "cd /data/homelogs && find -not -name ‘*.tar.gz‘ |xargs mv -f --backup=numbered -t /tmp/trash/ 2>/dev/null " commond2 = "cd /data/tradelogs && find -not -name ‘*.tar.gz‘ |xargs mv -f --backup=numbered -t /tmp/trash/ 2>/dev/null" subprocess.call(commond1, shell=True) subprocess.call(commond2, shell=True) trash()
END!
Linux 回收站
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。