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( ...
随机推荐
- Spring 学习笔记 数据绑定,校验,BeanWrapper 与属性编辑器
Spring 数据绑定,校验,BeanWrapper,与属性编辑器 Data Binding 数据绑定(Data binding)非常有用,它可以动态把用户输入与应用程序的域模型(或者你用于处理用户输 ...
- Java对图片压缩
背景:图片上传服务器时候的大小限制取消之后,上传图片太大导致前台显示加载缓慢 需求:服务器对接收到的图片进行压缩 方法:1.上传后的文件保存在临时文件夹“/usr/upload/tmp” 2.压 ...
- css渐变写法 从左到右渐变三种颜色示例;
background:linear-gradient(to right,#7f06a8,#a02bc2,#7f06a8)
- Size Assert
判断返回内容的大小
- 微信小程序之模板消息推送
最近在用sanic框架写微信小程序,其中写了一个微信消息推送,还挺有意思的,写了个小demo 具体见官方文档:https://developers.weixin.qq.com/miniprogram/ ...
- 2018-2-13-win10-UWP-动画
title author date CreateTime categories win10 UWP 动画 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17:23 ...
- xxd - 以十六进制形式表示
总览 (SYNOPSIS) xxd -h[elp] xxd [options] [infile [outfile]] xxd -r[evert] [options] [infile [outfile] ...
- 服务器搭建SVN
linux服务器搭建SVN https://blog.csdn.net/itbird58/article/details/80445521
- python基础教程2第20章 项目1:即时标记
simple_markup.py import sys, re from util import * print('<html><head><title>...&l ...
- leetcode-两个数组的交集
C++解题方法: class Solution { public: vector<int> intersection(vector<int>& nums1, vecto ...