The linux command 之 扩展
echo *
" * "字符意味着匹配文件名中的任意字符,shell会在执行echo命令之前把*扩展成其他内容。
一、路径扩展(pathname Expansion)
通过使用通配符来实现扩展的机制称为路径名扩展。
echo D*
echo *s
echo [[:uppper:]]*
echo /usr/*/share
二、波浪线扩展(Tilde Expansion)
tilde character(~) 有一个特殊的意义,当它用于单词的开头时,它将被扩展成用户的主目录名。如果没有指定用户名,则扩展到当前目录。
echo ~
echo ~foo
三、算术扩展(Arithmetic Expansion)
算术扩展使用:$((expression)),算术扩展只支持整数。

echo $(($((**)) * ))
四、花括号扩展(Brace Expansion)
用于花括号扩展的模式包含一个称为前导字符(preamble)的开头部分和一个称为附言(postscript)的结尾部分。花括号表达式本身可以包含一系列逗号分隔的字符串,也可以包含一系列整数或者单个字符。
[me@linuxbox ~]$ echo Front-{A,B,C}-Back
Front-A-Back Front-B-Back Front-C-Back
[me@linuxbox ~]$ echo Number_{..}
Number_1 Number_2 Number_3 Number_4 Number_5
[me@linuxbox ~]$ echo {..}
[me@linuxbox ~]$ echo {..}
[me@linuxbox ~]$ echo {Z..A}
Z Y X W V U T S R Q P O N M L K J I H G F E D C B A
花括号扩展也支持嵌套:
[me@linuxbox ~]$ echo a{A{,},B{,}}b
aA1b aA2b aB3b aB4b
在新建文件夹时操作方便:
[me@linuxbox ~]$ mkdir Photos
[me@linuxbox ~]$ cd Photos
[me@linuxbox Photos]$ mkdir {..}-{..}
[me@linuxbox Photos]$ ls
- - - - - -
- - - - - -
- - - - - -
- - - - - -
- - - - - -
- - - - - -
五、参数扩展(parameter expansion)
参数扩展在shell脚本中比直接用在命令行中有用,它的许多特性与系统存储小块数据以及给每个小块数据命名的性能有关。
[me@linuxbox ~]$ echo $USER
me
六、命令替换(Command Substitution)
命令替换可以将一个命令的输出作为一个扩展模式使用:
[me@linuxbox ~]$ echo $(ls)
Desktop Documents ls-output.txt Music Pictures Public Templates
Videos
[me@linuxbox ~]$ ls -l $(which cp)
-rwxr-xr-x root root -- : /bin/cp
[me@linuxbox ~]$ file $(ls -d /usr/bin/* | grep zip)
/usr/bin/bunzip2: symbolic link to `bzip2'
/usr/bin/bzip2: ELF 32-bit LSB executable, Intel 80386,
version 1 (SYSV), dynamically linked (uses shared libs), for
GNU/Linux 2.6.9, stripped
/usr/bin/bzip2recover: ELF 32-bit LSB executable, Intel 80386,
version 1 (SYSV), dynamically linked (uses shared libs), for
GNU/Linux 2.6.9, stripped
/usr/bin/funzip: ELF 32-bit LSB executable, Intel 80386,
version 1 (SYSV), dynamically linked (uses shared libs), for
GNU/Linux 2.6.9, stripped
/usr/bin/gpg-zip: Bourne shell script text executable
/usr/bin/gunzip: symbolic link to `../../bin/gunzip'
/usr/bin/gzip: symbolic link to `../../bin/gzip'
/usr/bin/mzip: symbolic link to `mtools'
在上面这个例子中,管道的输出为file命令的参数列表。
The linux command 之 扩展的更多相关文章
- 【linux】lvm扩展根分区
lvm扩展根目录 1.lvm的基本概念 physical volume (PV) 通常是一快硬盘.相当于一个物理设备,磁盘空间物理卷PV. volume group (VG) 相当于LVM的卷组,属于 ...
- 《The Linux Command Line》 读书笔记04 Linux用户以及权限相关命令
Linux用户以及权限相关命令 查看身份 id:Display user identity. 这个命令的输出会显示uid,gid和用户所属的组. uid即user ID,这是账户创建时被赋予的. gi ...
- 《The Linux Command Line》 读书笔记02 关于命令的命令
<The Linux Command Line> 读书笔记02 关于命令的命令 命令的四种类型 type type—Indicate how a command name is inter ...
- 《The Linux Command Line》 读书笔记01 基本命令介绍
<The Linux Command Line> 读书笔记01 基本命令介绍 1. What is the Shell? The Shell is a program that takes ...
- Linux Command Line Basics
Most of this note comes from the Beginning the Linux Command Line, Second Edition by Sander van Vugt ...
- Linux Command Line 解析
Linux Command Line 解析 0 处理模型 Linux kernel的启动包括很多组件的初始化和相关配置,这些配置参数一般是通过command line进行配置的.在进行后续分析之前,先 ...
- 15 Examples To Master Linux Command Line History
When you are using Linux command line frequently, using the history effectively can be a major produ ...
- linux php安装扩展方法 查找配置文件
如何在linux中查看nginx.apache.php.mysql配置文件路径了,如果你接收一个别人配置过的环境,但没留下相关文档.这时该怎么判断找到正确的加载文件路径了.可以通过以下来判断 1.判断 ...
- 10 Interesting Linux Command Line Tricks and Tips Worth Knowing
I passionately enjoy working with commands as they offer more control over a Linux system than GUIs( ...
随机推荐
- vue-router 动态路由
上一篇文章我们已经配置好了路由,下面,来说说如何实现动态路由. 比如,我想在 news 页点击列表项,跳转到对应项,如图所示: 这里引用的数据是豆瓣电影,地址: http://api.douban.c ...
- Day 16 : Python 时间模块[time,]datetime[]及第三方模块的下载与安装
在进行python程序开发时,除了可以使用python内置的标准模块外,还右许多第三方模块使用,可以在python官网找到. 在使用第三方模块时,需要下载并安装此模块,然后就可以使用标准模块一样导入并 ...
- Ansible随笔8
自定义模块的开发模式 1.决定自定义模块的存放路径 编辑/etc/ansible/ansible.cfg文件,修改library = /usr/share/ansible/. 这样就告诉ansible ...
- ASP.NET 中 ContentType 类型
在ASP.NET中使用Response.ContentType="类型名";来确定输出格式 不同的ContentType 会影响客户端所看到的效果.默认的ContentType为 ...
- UNLISTEN - 停止监听通知信息
SYNOPSIS UNLISTEN { name | * } DESCRIPTION 描述 UNLISTEN 用于删除一个现有的已注册的 NOTIFY 事件. UNLISTEN 取消当前 Postgr ...
- 标准 I/O (带缓冲)
标准IO中分文本流和二进制流 windows系统中:(1) 二进制流 - 换行符 '\n' (2) 文本流 - 换行符 ‘\r' '\n' linux 系统中:不区分文本流和二进制流:换行符 - ...
- IDEA 创建Spring cloud Eureka 注册中心
IDEA 创建Spring cloud Eureka 注册中心 一. 首先创建一个maven project Next之后填好groupId与artifactId,Next之后填好项目名与路径,点击F ...
- docker学习---搭建Docker LAMP环境
1.环境 系统版本:CentOS Linux release 7.4.1708 docker版本:docker-ce-18.09 主机IP:192.168.121.121 2.载入MySQL和PHP镜 ...
- notepad++去换行(简单、快捷)
文本处理问题 这个方式可以快捷处理, 不用Linux命令, linux 与window之间的文件转换很烦人, 这个方法可以处理
- nodejs的npm修改源
在国内用npm install时,速度总是不尽如人意,解决办法是修改npm的数据源 npm config set registry https://registry.npm.taobao.org 修改 ...