自己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监控远程主机