自己Ubuntu里面的一些小脚本
生活随笔
收集整理的這篇文章主要介紹了
自己Ubuntu里面的一些小脚本
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
我使用的是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) 這個(gè)是一個(gè)使用python寫的調(diào)節(jié)屏幕亮度的一個(gè)小腳本,非原創(chuàng)的哦 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 這是一個(gè)清理內(nèi)存的的腳本,當(dāng)你的內(nèi)存空間剩余小于800時(shí),就會(huì)幫你釋放內(nèi)存空間 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]) 這個(gè)腳本,是對(duì)文本的處理,當(dāng)你在網(wǎng)上直接copy的時(shí)候,有時(shí)候會(huì)copy到前面的行號(hào),如果行號(hào)另為一行,這個(gè)腳本就可以刪除行號(hào)轉(zhuǎn)載于:https://my.oschina.net/fsxchen/blog/108364
總結(jié)
以上是生活随笔為你收集整理的自己Ubuntu里面的一些小脚本的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Programming 2D Games
- 下一篇: 【HDOJ】4541 Ten Googo