Linux(Deepin)实用小脚本(原创)


以下命令您均可以复制到新建的xx.sh文件中,然后通过chmod +x xx.sh命令赋予可执行权限,以后您可以双击直接运行之。

1.Linux 实现随机壁纸切换

通过getdir函数来遍历文件夹下面的所有文件,并且给填充到a数组中去。

使用$(($RANDOM%$s))来生成一个小于s的随机数,这个数我们作为取的图片文件数组中的索引。使用之后,通过unset arr[idx]来移除数组中索引为idx的元素,同时通过b=("${b[@]}")将元素重新赋值给b,为什么要这样做呢,是因为你会发现移除元素只是将该索引下的元素标记为空,并没有从根本上改变内存大小,因此,我们需要重新赋值。

#!/bin/bash
#@Author: Oliver Chu

#You can set delay time below like this: 1s,1m,1h
delay=10m

#You can set an array of paths below.
path=("/home/oliver/Pictures/Download" "/home/oliver/Pictures/Planets")

a=()
function getdir(){
    for element in `ls $1`
    do  
        dir_or_file=$1"/"$element
        if [ -d $dir_or_file ]
        then 
            getdir $dir_or_file
        else
            a=(${a[@]} $dir_or_file)
        fi  
    done
}

for p in ${path[@]}
do
    getdir $p
done

function run(){
    b=("${a[@]}")
    echo "Quantity of wallpapers:" ${#b[@]}
    s=${#b[@]}
    while [ $s -gt 0 ]
    do
        idx=$(($RANDOM%$s))
        cur=${b[idx]}
        echo `date +%H:%M:%S` $cur
        #For Deepin OS,you can type the command below:
        qdbus --literal com.deepin.wm /com/deepin/wm com.deepin.wm.ChangeCurrentWorkspaceBackground "$cur"
        #For Ubuntu, you can type the command below:
        #gsettings set org.gnome.desktop.background picture-uri "$cur"
        #For other Linux based Operation,you can search "XX 命令换壁纸" via Google, Baidu, etc.
        unset b[idx]
        b=("${b[@]}")
        s=$((s-1))
        sleep $delay
    done
}
while :
do
    run
done
2.Deepin/Ubuntu中查看已连接过的WiFi密码

已经连接过的WiFi热点位于/etc/NetworkManager/system-connections,您只需要查看他们就可以知道密码和加密类型,非常实用。

cd /etc/NetworkManager/system-connections
ls -all
# You can see a list of SSID which you have been connected.
sudo cat {the file you need to cat}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值