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( ...
随机推荐
- jquery 临时存值
function toSort(orderBy) { if (orderBy == $('#orderBy').data("order")) {// 再次点击同一个排序时 $('# ...
- 51-Ubuntu-打包压缩-1-打包压缩简介
打包压缩是日常工作中备份文件的一种方式 在不同操作系统中,常用的打包压缩方式是不同的 Windows 常用 rar Mac 常用 zip Linux 常用 tar.gz
- 防止DDOS攻击有效方法:隐藏服务器真实IP
如今,网站服务器的安全受到越来越多的重视,但是难免会遇到黑客使用DDoS攻击网站,为了网站的安全通常都会做好防御,其中防止DDoS攻击有效方法:隐藏服务器真实IP ,该技术能够有效地保护网站的安全. ...
- vim 中 ctags的应用
为了方便查询代码段中代码的最终的定义 在linux的vim便以其中可以使用ctags 使用步骤: 1. 安装 ctags : sudo apt-get install ctags 2. 生 ...
- 45. Collection
因为Collection是接口我们不能直接实例化,所以我们下面的例子都是采用多态实例化实现类ArrayList类 1. Collection中常用方法 添加: add() 添加一个元素到集合中 ...
- JUC 一 ReentrantLock 可重入锁
java.util.concurrent.locks ReentrantLock即可重入锁,实现了Lock和Serializable接口 ReentrantLock和synchronized都是可重入 ...
- 【基础】Hint控制语句执行
mysql常用的hint对于经常使用oracle的朋友可能知道,oracle的hint功能种类很多,对于优化sql语句提供了很多方法.同样,在mysql里,也有类似的hint功能.下面介绍一些常用的. ...
- js条件语句,用if...else if....else方程ax2+bx+c=0一元二次方程。求根
if 语句 - 只有当指定条件为 true 时,使用该语句来执行代码 if...else 语句 - 当条件为 true 时执行代码,当条件为 false 时执行其他代码 if...else if... ...
- 【Codeforces Round #429 (Div. 2) B】 Godsend
[Link]:http://codeforces.com/contest/841/problem/B [Description] 两个人轮流对一个数组玩游戏,第一个人可以把连续的一段为奇数的拿走,第二 ...
- Android中的Service详解
今天我们就来介绍一下Android中的四大组件中的服务Service,说到Service, 它分为本地服务和远程服务:区分这两种服务就是看客户端和服务端是否在同一个进程中,本地服务是在同一进程中的,远 ...