1.特殊符号:
' ' 单引号
单引号的内容 写什么就是什么,不会被当成特殊字符.
单引号实例:
[root@oldboyedu-sh01 ~]# echo '$123'
$123
" " 双引号
双引号里面的内容会被解析
双引号实例:
[root@oldboyedu-sh01 ~]# echo "$123"
23
## $1 被当成了变量,而在单引号中不会出现这种问题
` ` (键盘中 1 的右边),称为 反引号
反引号会让引号内的内容优先执行
反引号 实例:
[root@oldboyedu-sh01 ~]# ls -l `ls`
-rw-r--r--. 1 root root 0 Apr 9 11:14 2
-rw-------. 1 root root 1162 Mar 22 12:05 anaconda-ks.cfg
-rw-r--r--. 1 root root 21736 Mar 22 12:05 install.log
-rw-r--r--. 1 root root 5890 Mar 22 12:04 install.log.syslog
-rw-r--r--. 1 root root 242 Apr 9 10:02 oldboy.txt
! 感叹号
find排除
find chenleilei/ -type f ! -name "2" -name "*"
#排除多个请看下面的实例
感叹号为取反的意思 (find 命令中 ! 只能排除一个文件或者文件夹,但可以在后面接
egrep -v 来排除多个)
感叹号实例:
[root@oldboyedu-sh01 ~]# find chenleilei/ -type f -name "*" | egrep -v "3|2|1"
chenleilei/7
chenleilei/8
chenleilei/9
chenleilei/5
chenleilei/4
chenleilei/6
^符号 以XX开头
[root@chenleilei ~]# grep ^7 3.txt
743q9hf9g87rfg23
& & 并且 (一个命令执行成功后再执行下一个命令)
例子:
ifdown eth0 && ifup eth0
[] 代表的是中括号中的任意一个
例子:[root@chenleilei
~]# ls [1,2,3].txt
1.txt 2.txt 3.txt
* 任意一个或者多个字符,或匹配所有
例子: [root@chenleilei ~]# ls *.txt
1.txt
2.txt 3.txt
? 任意一个单个字符
例子:[root@chenleilei ~]# ls ?.txt
> 覆盖输出重定向
echo '123' >1.txt
>> 追加输出重定向
echo '123' >1.txt
< 输入重定向
cat >1.txt < eof
1111111
eof 输入重定向
<< 追加输入重定向
cat >1.txt<<eof
1111111
eof
[-] 代表一个范围 如 [a-zA-z]
例子: [0-9] 代表括号内得0到9得任意字符会被匹配
[^] 非得意思如 [^abc] -- 只要不是abc其他都行 排除得意思
{ } 生成序列
例子: touch {1..10}.txt
. 当前目录
.. 上一级目录
基础正则:
{..} 查找或删除文件时指定多个文件类型 (查询)
如: ls {*.txt,*.jpg}
[root@oldboyedu-sh01 chenleilei]# ls {*.txt,*.jpg}
1.jpg 1.txt
{..} echo 总 它是指定 一个数列 和数列间得间隔 (生成数列)
[root@oldboyedu-sh01 chenleilei]# echo {1..10..3}
1 4 7 10
{..} 同时1.{,.bak} 也可以进行备份 (备份)
[root@oldboyedu-sh01 chenleilei]# cp 1.txt{,.bak}
[root@oldboyedu-sh01 chenleilei]# ls
1 10 1.jpg 1.txt 1.txt.bak 2 3 4 5 6 7 8 9
^ 以什么开头
[root@oldboyedu-sh01 chenleilei]# ls 99*.txt
9992ef9.txt 9999999999.txt
^$ 表示为 空行
[root@oldboyedu-sh01 ~]# grep --color=auto -n '^$' oldboy.txt
3:
8:
扩展实例:
统计一个文件中 每个字符使用得次数
[root@oldboyedu-sh01 ~]# grep -o '[0-9]' oldboy.txt |sort |uniq -c
[root@oldboyedu-sh01 ~]# grep -o '[0-9]' oldboy.txt | sort | uniq -c
8 0
1 1
6 4
1 5
2 8
2 9
