日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

shell example01

發布時間:2023/11/27 生活经验 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 shell example01 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

條件判斷

if [[ -e ${1} ]]; thenecho "$(tput setaf 2) found ${1} $(tput sgr0)"cat ${1}
elseecho "$(tput setaf 1) not found ${1} $(tput sgr0)"exit 1
fi//簡化[[ -e ${1} && -e ${2} ]] && cat ${1} > ${2}//判斷取反txt='4.txt'if ! [[ -e ${txt} ]]; thentouch ${txt}echo "touch ${txt}; name length ${#txt}"
fi//多重選擇bold=$(tput bold)
underline=$(tput smul)
normal=$(tput sgr0)
red=$(tput setaf 1)
green=$(tput setaf 2)if [[ -e 'a1.txt' ]]; thenecho "${bold}${underline}${green} search a{1..5}.txt ${normal}"ls a{1..5}.txt 2> log.txt
elif [[ -e 'b1.txt' ]]; thenecho "${bold}${underline}${green} search b{1..5}.txt ${normal}"ls b{1..5} txt 2>> log.txt
elseecho "${bold}${underline}${red} create a{1..4}.txt ${normal}"touch a{1..5}.txt
fi

顯示時間

//查找文件
start=$(date +%s)
echo 'start search'find ~/ -name '*.txt' &> log.txtecho 'end search'end=$(date +%s)         //%s以秒為單位
difference=$(( end - start))
echo "Time is ${difference} seconds".//顯示具體的執行時間
echo 'start search'
time find ~/ -type f -name '*txt' &> log.txt     //僅僅是文件
echo 'end search'//計時器
echo '- Count Start'
tput sc    //存儲光標位置
count=0while [[ ${count} -lt 20 ]]
dolet count++sleep 1      //延遲一秒tput rc      //恢復光標位置tput ed     //清除從當前光標位置到行尾之間的所有內容echo "- ${count}"
doneecho "- Count End"

循環

//循環創建文件
for i in file{1..9}.txt
doif [[ -e ${i} ]]thenecho "find ${i} skip"elseecho "start create ${i}"touch ${i}
fi
done
echo "finished"//判斷空文件
files=$(echo *.txt)
normal=$(tput sgr0)
type="%-10s %-8s\n"printf "$(tput bold)${type}" name blank
printf ${normal}
for file in ${files}; docheck=truecolor=$(tput setaf 1)test -s ${file}  && check=false color=$(tput setaf 2)printf "${color}${type}" ${file} ${check}printf ${normal}
done

簡單編輯

//去除空白
cat $1 | sed '/s //g' > new.log             //sed 's/要被取代的字串/新的字串/g'   //對特定格式的文檔計算重復值
//log.txt
account1:passwd1
account2:passwd2
account3:passwd3
account2:passwd4
account4:passwd5
account6:passwd6
account1:passwd7//
awk -F: 'x[$1]++ {print $1 " is duplicated"}'  log.txt           //awk -F 指定分割字符 

轉載于:https://www.cnblogs.com/jinkspeng/p/5125677.html

總結

以上是生活随笔為你收集整理的shell example01的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。