特殊符号

简介:

代表0个或多个任意字符
[root@localhost ~]# ls
1.txt 3.txt 5.txt bb.txt filename test.txt
2.txt 4.txt anaconda-ks.cfg cc.txt test.tar
[root@localhost ~]# ls .txt
1.txt 2.txt 3.txt 4.txt 5.txt bb.txt cc.txt test.txt
[root@localhost ~]# ls test.

test.tar test.txt

? 代表一个字符

[root@localhost ~]# ls test.ta?
test.tar
[root@localhost ~]# ls ?.txt
1.txt 2.txt 3.txt 4.txt 5.txt

#注释符号,后面内容不被执行

[root@localhost ~]# #dnfsfndfi
[root@localhost ~]# ##ksdjsldkl
[root@localhost ~]# djij
-bash: djij: 未找到命令

\ 脱义字符,
这个字符会将后面的特殊字符(如*)还原为普通字符

[root@localhost ~]# ls -d 1.txt*
ls: 无法访问1.txt*: 没有那个文件或目录

cut 命令是用来截取某一字段,其格式为 cat -d '分割字符'[-cf] n ,n为数字
-d : 后面跟分割符,分隔符要用单引号括起来
-c :后面接的是第几块字符
-f :后面跟的是第几区块

[root@localhost ~]# cat /etc/passwd |head -2 |cut -d ':' -f 1
root
bin
[root@localhost ~]# cat /etc/passwd |head -2 |cut -d ':' -f 1,2
root:x
bin:x
[root@localhost ~]# cat /etc/passwd |head -2 |cut -d ':' -f 1-4
root:x:0:0
bin:x:1:1

sort 命令排序 格式:sort [-t 分隔符] [-kn1,n2] [nru] n1 n2 为数字
-t:后面跟分隔符,作用同cut
-n:后面使用纯数字排序
-r :反向排序
-u :表示重复
-kn1,n2:表示n1 区间排序到n2区间,可以只写-kn1 即对n1字段排序

[root@localhost ~]# sort /etc/passwd
adm:x:3:4:adm:/var/adm:/sbin/nologin
avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
halt:x:7:0:halt:/sbin:/sbin/hal

wc -l 统计行数
[root@localhost ~]# wc -l 1.txt
10 1.txt
wc -w 统计词
[root@localhost ~]# wc -m /etc/passwd
883 /etc/passwd
wc -m 统计字符数
[root@localhost ~]# wc -m 1.txt
385 1.txt

uniq 用来删除重复的行,配合-c使用,统计重复的行数
sort 2.txt |uniq 先排序后删除重复
[root@localhost ~]# vim 2.txt
[root@localhost ~]# uniq 2.txt
wassadjaajjj123
111111
222222
333333
111111
121212
222222
[root@localhost ~]# uniq -c 2.txt
1 wassadjaajjj123
1 111111
3 222222
1 333333
2 111111
2 121212
1 222222
[root@localhost ~]# sort 2.txt |uniq
111111
121212
222222
333333
wassadjaajjj123

tee 后面跟文件名,类似于重定向> 还有一个作用是显示把内容显示在屏幕上
>跟文件是清空文件的内容
tee -a 表示追加

[root@localhost ~]# sort 2.txt |uniq -c |tee 3.txt
3 111111
2 121212
4 222222
1 333333
1 wassadjaajjj123
[root@localhost ~]# cat 3.txt
3 111111
2 121212
4 222222
1 333333
1 wassadjaajjj123
[root@localhost ~]# > 3.txt
[root@localhost ~]# cat 3.txt

tee -a 表示追加

[root@localhost ~]# sort 2.txt |uniq -c |tee 3.txt
3 111111
2 121212
4 222222
1 333333
1 wassadjaajjj123
[root@localhost ~]# sort 2.txt |uniq -c |tee -a 3.txt
3 111111
2 121212
4 222222
1 333333
1 wassadjaajjj123
[root@localhost ~]# cat 3.txt
3 111111
2 121212
4 222222
1 333333
1 wassadjaajjj123
3 111111
2 121212
4 222222
1 333333

tr 命令替换字符,常用来处理文档中处理文档出现的特殊字符

[root@localhost ~]# ac='acer'
[root@localhost ~]# echo $ac
acer
[root@localhost ~]# echo ac
ac
[root@localhost ~]# echo ac |tr '[a-z]' '[A-Z]'
AC
[root@localhost ~]# cat /etc/passwd |head -2 |tr '[a-z]' '[A-Z]'
ROOT:X:0:0:ROOT:/ROOT:/BIN/BASH
BIN:X:1:1:BIN:/BIN:/SBIN/NOLOGIN

split 用于切割文档,常用的选项为-b和-l
-b 表示依据大小来分割文档,单位为byte

!$ 表示上一条命令的最后一个变量
[root@localhost ~]# ls 1.txt
1.txt
[root@localhost ~]# ls !$
ls 1.txt
1.txt
[] 代表字符组合中的任意一个

[root@localhost ~]# cat /etc/passwd |head -2 |tr '[a-z]' '[A-Z]'
ROOT:X:0:0:ROOT:/ROOT:/BIN/BASH
BIN:X:1:1:BIN:/BIN:/SBIN/NOLOGIN

command1;command2 使用;表示不管command1是否执行成功 command2都会执行
command1&&command2 使用&&表示command1执行成功 后command2才会执行,否则不执行
command1||command2 使用||表示command1执行不成功 command2才会执行

[root@localhost ~]# ls
anaconda-ks.cfg cc.txt split_dir test.txt xab xad xaf xah
bb.txt filename test.tar xaa xac xae xag xai
[root@localhost ~]# touch test1 test2
[root@localhost ~]# ls test2 ; touch test2
test2
[root@localhost ~]# ls test2 && touch test2
test2
[root@localhost ~]# cat 3.txt || touch 3.txt
cat: 3.txt: 没有那个文件或目录
[root@localhost ~]# ls
3.txt bb.txt filename test1 test.tar xaa xac xae xag xai
anaconda-ks.cfg cc.txt split_dir test2 test.txt xab xad xaf xah




本文转自 yzllinux 51CTO博客,原文链接:http://blog.51cto.com/12947851/2060455,如需转载请自行联系原作者

相关文章
|
4月前
去掉字符串前后空格/去掉字符串中所有空格(包括中间连续空格)/去掉所有全角半角空格/去掉所有全角半角 空格
去掉字符串前后空格/去掉字符串中所有空格(包括中间连续空格)/去掉所有全角半角空格/去掉所有全角半角 空格
hutool 判断字符串是否全部为字母组成,包括大写和小写字母和汉字
hutool 判断字符串是否全部为字母组成,包括大写和小写字母和汉字
|
5月前
|
搜索推荐
特殊符号
特殊符号
27 0
|
8月前
正则表达式中的字符详解
正则表达式中的字符详解
63 1
|
8月前
输入一个字符,判断该字符是大写英文字母,小写英文字母,空格,还是其它字符
输入一个字符,判断该字符是大写英文字母,小写英文字母,空格,还是其它字符
写几个正则表达式:只允许输入汉字、数字、字母、中英文小括号,并且10个字符以内|只允许输入汉字、数字、字母、英文小括号|电话号码正则表达式
写几个正则表达式:只允许输入汉字、数字、字母、中英文小括号,并且10个字符以内|只允许输入汉字、数字、字母、英文小括号|电话号码正则表达式
170 0
正则表达式 - 最常用正则表达式大全(数字、字符、特殊)
正则表达式 - 最常用正则表达式大全(数字、字符、特殊)
617 0
忽略大小写比较字符串大小
一般我们用 strcmpstrcmp 可比较两个字符串的大小,比较方法为对两个字符串从前往后逐个字符相比较(按 ASCII 码值大小比较),直到出现不同的字符或遇到 \0 为止。 如果全部字符都相同,则认为相同;如果出现不相同的字符,则以第一个不相同的字符的比较结果为准。 但在有些时候,我们比较字符串的大小时,希望忽略字母的大小,例如 Hello 和 hello 在忽略字母大小写时是相等的。 请写一个程序,实现对两个字符串进行忽略字母大小写的大小比较。
274 0

热门文章

最新文章