guo20082200的个人博客分享 http://blog.sciencenet.cn/u/guo20082200

博文

linux_centos第12次课正则表达式

已有 1896 次阅读 2015-8-17 11:10 |个人分类:Linux学习|系统分类:科研笔记| style, color, 表达式

12次课正则表达式

[root@guohuiqiang ~]# alias

aliascp='cp -i'

aliasl.='ls -d .* --color=auto'

aliasll='ls -l --color=auto'

aliasls='ls --color=auto'

aliasmv='mv -i'

aliasrm='rm -i'

aliaswhich='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

 

[root@ghq ~]# a='pwd'

[root@ghq ~]# echo $a

Pwd

声明一个全局变量: export,是当前的shell和其子shell,如果再打开一个终端,则不会生效。要想再另一个终端生效,需要修改配置文件:etc/profile, etc/bashrcetc/.bashrc      etc/.bash_profile

修改umask,修改etc/profile文件。

 

[root@ghq ~]#ls

~]#                   aaa.log          Downloads           mkfs.ext  Templates

2014zuihouyiwang.log  aaa.txt          err.out             Music     Videos

2015.log              all.log          guo                 new_file

2.log                 anaconda-ks.cfg  guo.log             Pictures

aaa                   Desktop          install.log         Public

aaaa                  Documents        install.log.syslog  sss.log

[root@ghq ~]#ls [aaa].txt(为啥中括号不起作用啊?)

ls:cannot access [aaa].txt: No such file or directory

 

[root@ghq~]#touch A.txt

[root@ghq ~]#ls [a-zA-Z].txt (新创建一个文件有用)

A.txt

[root@ghq ~]#ls [a-z].txta-z为啥包括了A??)

中括号只表示其中的任意一个字符

A.    txt

 

连接符:

[root@ghq~]#cm1 && cm2

[root@ghq~]#cm1 || cm2

[root@ghq~]#cm1 ; cm2

 

命令cut的使用,功能不是很强大

[root@ghq~]#cd /pub

[root@ghqpub]#ls

aa  aming aminghard  bbb.txt  ccc.txt guo  lei  passwd ps.out

[root@ghq pub]#cut -d ':' -f 1 passwd |head

root

bin

daemon

adm

lp

sync

shutdown

halt

mail

uucp

 

[root@ghqpub]#cut --version

cut(GNU coreutils) 8.4

Copyright(C) 2010 Free Software Foundation, Inc.

LicenseGPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.

Thisis free software: you are free to change and redistribute it.

Thereis NO WARRANTY, to the extent permitted by law.

 

Writtenby David M. Ihnat, David MacKenzie, and Jim Meyering.

 

[root@ghq pub]#echo 'abc' |tr 'a' 'b'tr 替换)

bbc

[root@ghqpub]#echo 'abc' |tr 'a-z' 'A-Z'

ABC

 

正则表达式(grep egrep sed awk

 

[root@ghqpub]#grep 'root' passwd

root:x:0:0:root:/root:/bin/bash

operator:x:11:0:operator:/root:/sbin/nologin

[root@ghqpub]#grep 'root' passwd -n

1:root:x:0:0:root:/root:/bin/bash

11:operator:x:11:0:operator:/root:/sbin/nologin

[root@ghqpub]#grep 'root' passwd -x

[root@ghqpub]#grep 'root' passwd -c

2

[root@ghq pub]#grep --color=auto 'root' passwd

root:x:0:0:root:/root:/bin/bash

operator:x:11:0:operator:/root:/sbin/nologin



12.docx

 




https://blog.sciencenet.cn/blog-575910-913698.html

上一篇:linux_centos第11次课,shell基础部分
下一篇:linux_centos第14次课 shell基础
收藏 IP: 180.175.196.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-9-27 23:31

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部