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 之 扩展的更多相关文章

  1. 【linux】lvm扩展根分区

    lvm扩展根目录 1.lvm的基本概念 physical volume (PV) 通常是一快硬盘.相当于一个物理设备,磁盘空间物理卷PV. volume group (VG) 相当于LVM的卷组,属于 ...

  2. 《The Linux Command Line》 读书笔记04 Linux用户以及权限相关命令

    Linux用户以及权限相关命令 查看身份 id:Display user identity. 这个命令的输出会显示uid,gid和用户所属的组. uid即user ID,这是账户创建时被赋予的. gi ...

  3. 《The Linux Command Line》 读书笔记02 关于命令的命令

    <The Linux Command Line> 读书笔记02 关于命令的命令 命令的四种类型 type type—Indicate how a command name is inter ...

  4. 《The Linux Command Line》 读书笔记01 基本命令介绍

    <The Linux Command Line> 读书笔记01 基本命令介绍 1. What is the Shell? The Shell is a program that takes ...

  5. Linux Command Line Basics

    Most of this note comes from the Beginning the Linux Command Line, Second Edition by Sander van Vugt ...

  6. Linux Command Line 解析

    Linux Command Line 解析 0 处理模型 Linux kernel的启动包括很多组件的初始化和相关配置,这些配置参数一般是通过command line进行配置的.在进行后续分析之前,先 ...

  7. 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 ...

  8. linux php安装扩展方法 查找配置文件

    如何在linux中查看nginx.apache.php.mysql配置文件路径了,如果你接收一个别人配置过的环境,但没留下相关文档.这时该怎么判断找到正确的加载文件路径了.可以通过以下来判断 1.判断 ...

  9. 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( ...

随机推荐

  1. 使用uc进行手机页面调试

    最近使用uc浏览器的时候发现了,一个有趣的现象,就是uc会处理h5web app为全屏,并屏蔽一些手机上的操作,这样就会使web app更加接近本地应用.所以就研究 了一下uc的手机调试. 1.准备工 ...

  2. VIM查找空格

    匹配1到多个空格 /\s\+ 或者开启very magic模式 /\v\s+

  3. Linux中的网络管理——网络配置及命令

    Linux网络配置 在Linux中配置IP地址的方法有以下这么几种: 图形界面配置IP地址(操作方式如Windows系统配置IP,但在实际生产中,我们并不建议在我们的服务器上安装Linux的图形界面, ...

  4. 优雅地使用 VSCode 来编辑 vue 文件

    javascript visual-studio-code vue.js 当然 vscode 对 vue 也不是原生支持的,今天来扒一扒如何配置 vscode 以便优雅地编辑 vue 文件 先来扒一扒 ...

  5. PHP算法之有效的括号

    给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭合.左括号必须以正确的顺序闭合.注意空字符串可被认为是 ...

  6. element-UI 点击一行,背景色变化

    代码: @row-click="rowClick" 当某一行被点击时会触发该事件 :row-class-name="tableRowClassName"  可以 ...

  7. hadoop.io.native.NativeID$Windows.access0 报错问题解决

    系统:win10 hadoop-2.6.0版本 java:1.8 版本32位   wordcount在本地运行时报错: Exception in thread "main" jav ...

  8. HttpUrlConnection类基本使用

    这个类用来模拟浏览器向服务器发送请求和接收响应 注意: HttpUrlConnection对象简称huc对象 1)获取huc对象向url构造中传递url字符串,并调用openconnection方法即 ...

  9. 安装和使用pyspider框架时遇到的问题

    安装pyspider, 直接cmd中输入 pip install pyspider, 而后提示报错 从网上找到解决方法,pycurl需要根据python版本采用wheel方法安装. 下载链接为http ...

  10. element中的tree组件实现菜单分配

    返回的菜单数据 tree组件的使用 <el-tree ref="menuList" // :data="menuList" // 展示数据 :props= ...