Linux shell 15课时笔记

单引号实现所见即所得
双引号内的变量会被转义
反引号 等价于 $()
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

猜你喜欢

转载自blog.51cto.com/90856/2156891