1. 程式人生 > >Linux shell 15課時筆記

Linux shell 15課時筆記

print 管道 -a rip sum () md5sum 空格 隨機數

單引號實現所見即所得
雙引號內的變量會被轉義
反引號 等價於 $()
liuyu@talesun:~$ a=‘hello‘
liuyu@talesun:~$ echo $a
hello
liuyu@talesun:~$ b="${a},world"
liuyu@talesun:~$ echo $b
hello,world
liuyu@talesun:~$ c=whoami
liuyu@talesun:~$ echo $c
liuyu
liuyu@talesun:~$ d=$(whoami)
liuyu@talesun:~$ echo $d
liuyu
liuyu@talesun:~$ e=whoami
liuyu@talesun:~$ echo $e
whoami
liuyu@talesun:~$ f=$e
liuyu@talesun:~$ echo $f
liuyu
liuyu@talesun:~$

管道 | 重定向 > 追加 >>
seq 1 2 10
標準輸出 1 標準輸入0 標準錯誤輸出 2

test.txt #清空一個文件
取出來你使用最多的5條命令
history > history.txt
cat history.txt | awk ‘{print $2}‘ | sort | uniq -c | sort -nr | head -5

別名 alias ll=‘ls -l‘

永久生效 /etc/profile 全局生效
家目錄下的 .bashrc 文件中
. 或 source .bashrc #加載這個配置文件

終端錄屏 script -a action.log -t 2>time.log
scriptreplay time.log action.log

expr 1 + 2 #操作符兩邊要有空格
expr 2 * 3
let a=2+3
echo $a
b=$[2+3]
echo $b
c=$((2+3))
echo $c
echo 2+3 | bc

偽隨機數
echo $RANDOM
for i in seq 10000
do
echo $RANDOM >>1.txt

done
echo $(($RANDOM%10))
echo $((RANDOM)) | md5sum | cut -c 1-8

Linux shell 15課時筆記