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}

你可能感兴趣的:(Linux)