分享

1. bash简介及通配符、扩展通配符

 老段001 2013-04-27

当我们执行一些命令的时候,很多的命令是由bash提供的。如果我们想知道某个命令是否是由bash内置的命令的话,我们可以使用type

bash内置命令:bash  通配符 扩展通配符 rhce学习bash linux shell shell编程 shell脚本

type

wps clip image 28014 1. bash简介及通配符、扩展通配符

fc

alias

wps clip image 6311 1. bash简介及通配符、扩展通配符

wps clip image 9761 1. bash简介及通配符、扩展通配符

wps clip image 27376 1. bash简介及通配符、扩展通配符

如果想让我们所做的别名继续生效的话,那么我们要写入到.bashrc bash 通配符 扩展通配符 rhce

wps clip image 17600 1. bash简介及通配符、扩展通配符

有很多的shell内置的命令,如果我们想关闭某个命令的话,那么就可以使用

enable :用来开启或者关闭某个内置命令的功能

wps clip image 11974 1. bash简介及通配符、扩展通配符

wps clip image 31173 1. bash简介及通配符、扩展通配符

wps clip image 28485 1. bash简介及通配符、扩展通配符

*和?
*匹配所有的、任意长度的字符(匹配不了隐藏文件)

ls *  —> 显示当前目录下面所有的 非隐藏文件

wps clip image 30266 1. bash简介及通配符、扩展通配符

匹配一个字符,是一个不是0个,也不是多个,只能匹配一个

[] :匹配一个字符,不是0个,也不是多个

数字:[0-9] -是到的意思

wps clip image 10794 1. bash简介及通配符、扩展通配符

字母:[a-z] [A-Z] [a-zA-Z]

wps clip image 30305 1. bash简介及通配符、扩展通配符

类:

[[:alnum:]]: 所有的字母和数字

wps clip image 21079 1. bash简介及通配符、扩展通配符

[[:alpha:]] 代表英文大小写字母 a-z A-Z

wps clip image 21136 1. bash简介及通配符、扩展通配符

[[:blank:]] 代表空格键与 [Tab] 按键两者

wps clip image 21449 1. bash简介及通配符、扩展通配符

[[:digit:]] :表示数字 [0-9]

wps clip image 20454 1. bash简介及通配符、扩展通配符

[[:space:]]

[[:lower:]]:表示小写字母的[a-z]

wps clip image 3047 1. bash简介及通配符、扩展通配符

[[:upper:]] :表示大写字母[A-Z]

wps clip image 30669 1. bash简介及通配符、扩展通配符

以上我们所做的这些都是bash给我们提供的一些功能。这些功能我们可以选择性的开启或者关闭

set -o

wps clip image 397 1. bash简介及通配符、扩展通配符

1. noclobber 现在是off的,就说明我们现在可以执行 覆盖(>)

wps clip image 13413 1. bash简介及通配符、扩展通配符

set -o 功能

如果想关闭的话就是set +o 功能

set +o noclobber

wps clip image 16971 1. bash简介及通配符、扩展通配符


关闭通配符功能: set -o noglob

关闭通配符:

wps clip image 8509 1. bash简介及通配符、扩展通配符

wps clip image 13991 1. bash简介及通配符、扩展通配符

shell选项可以改变shell的工作模式

shell options ==> shopt

删除的时候是删除不了隐藏文件的

*不会匹配隐藏文件

wps clip image 15128 1. bash简介及通配符、扩展通配符

wps clip image 3430 1. bash简介及通配符、扩展通配符

直接删除,是删除不了隐藏文件的,因为*根本不能匹配隐藏文件

现在想匹配:shopt来更改shell的属性

shopt -s 功能:启用某个功能

shopt -u 功能; 关闭某个功能

wps clip image 11914 1. bash简介及通配符、扩展通配符

shopt -s dotglob

shopt -u dotglob

wps clip image 7719 1. bash简介及通配符、扩展通配符

文件名的扩展:

linux里表示硬盘使用的sdxx的取值范围是a-z),如果说硬盘数量太多sdz,现在还有几块硬盘,如何表示?sdaa, sdab, sdac….sdaz, sdba, sdbb

电脑里有很多的硬盘,我现在想对所有的硬盘来进行操作(不是对分区)。我如何表示所有的硬盘?

如果说sdx, sdxy?

sda[a-z]?   —> sdax 就不能把sda sdb匹配出来

sda? –> sdab sda2,又不想匹配分区所以sda2不能显示

如果想实现这种功能的话,我们可以使用扩展的通配符.

如果想显示多个多个字母的话:

shopt -s extglob; ls sd+([a-z])

wps clip image 17574 1. bash简介及通配符、扩展通配符

要查找出来sd后面有多个字母的,这样就把sd后面有数字的那些全部排出了.

有了extglob,可以匹配更多的模式

?():括号里的值可以有0个或者1

wps clip image 26071 1. bash简介及通配符、扩展通配符

的意思是后面括号里所表示的内容要出现1次或者0

wps clip image 9765 1. bash简介及通配符、扩展通配符

*():括号里的值可以是0个或者多个

wps clip image 5065 1. bash简介及通配符、扩展通配符

+():括号里的值可以是1个或者多个

@():匹配括号里出现一次的情况

wps clip image 12451 1. bash简介及通配符、扩展通配符

wps clip image 5233 1. bash简介及通配符、扩展通配符

要把那些abc后面出现一次mp3或者txt的文件找出来。是一次,不能是多次

所以abc.txt.txt就没有匹配,因为它出现里两次txt

!():与@()相反:课后题自己思考

shopt -p

*表示匹配所有的字符,但如果匹配某类之外其他所有的字符,可以是GLOBIGNORE

wps clip image 14055 1. bash简介及通配符、扩展通配符

*匹配所有的,不管你是什么字符。

我现在不想匹配数字,也就是sda*,这个*要表示除了数字以外其他所有的字符

wps clip image 12050 1. bash简介及通配符、扩展通配符

GLOBIGNORE=sda*[0-9]

*匹配的时候,要把GLOBIGNORE所代表的值给去除

对应视频下载地址:http://www./?p=962

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多