以下命令您均可以複製到新建的
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 {what file you need to cat}