zoukankan      html  css  js  c++  java
  • 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!

  • 相关阅读:
    CTreeCtrl::HitTest
    GetLastError()函数返回值及含义
    最大轮廓和投影 转
    一些Python黑客脚本
    win10系统架构调用
    rootkit基础
    面向对象编程
    机器学习概述
    XXE攻击
    浏览器安全
  • 原文地址:https://www.cnblogs.com/changbo/p/7054634.html
Copyright © 2011-2022 走看看