自己Ubuntu里面的一些小脚本
生活随笔
收集整理的這篇文章主要介紹了
自己Ubuntu里面的一些小脚本
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
我使用的是Ubuntu12.10,下面介紹一下本人常用的一些腳本 1、 import dbus bus = dbus.SessionBus() proxy = bus.get_object('org.gnome.SettingsDaemon','/org/gnome/SettingsDaemon/Power') iface=dbus.Interface(proxy,dbus_interface='org.gnome.SettingsDaemon.Power.Screen') iface.SetPercentage(100) 這個是一個使用python寫的調節屏幕亮度的一個小腳本,非原創的哦 2、 #/bin/bash MEM=`free -m | head -n 2 | tail -n 1 | cut -d" " -f1- | awk '{print $4}'` echo "$MEM" if [ "$MEM" -le 800 ]; thensyncecho 3 | sudo tee /proc/sys/vm/drop_cachesecho haha elseexit fi 這是一個清理內存的的腳本,當你的內存空間剩余小于800時,就會幫你釋放內存空間 3、 #!/usr/bin/python # delete the lines begin with number import os, re import sys path = os.path.abspath(os.curdir) OpenFileHandle = open(path + '/'+sys.argv[1], 'r') WriteFileHandle = open(path + '/' + 'Temp', 'w') for fileList in OpenFileHandle.readlines():if re.match('^[0-9]', fileList) is not None:continueelse:WriteFileHandle.write(fileList) OpenFileHandle.close() WriteFileHandle.close()os.remove(sys.argv[1]) os.rename('Temp',sys.argv[1]) 這個腳本,是對文本的處理,當你在網上直接copy的時候,有時候會copy到前面的行號,如果行號另為一行,這個腳本就可以刪除行號轉載于:https://my.oschina.net/fsxchen/blog/108364
總結
以上是生活随笔為你收集整理的自己Ubuntu里面的一些小脚本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Programming 2D Games
- 下一篇: ubuntu下nagios监控远程主机