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!

浙公网安备 33010602011771号