the linux command line学习笔记之二
有关命令扩展(Expansion)
echo:
[root@centos7rzc ~]# echo * #*被扩展成文件名 0227_2.sh 02273.sh 0227.sh anaconda-ks.cfg Desktop Documents Downloads err.txt initial-setup-ks.cfg Music perl5 Pictures Public Templates test test.txt Videos vmware-tools-distrib [root@centos7rzc ~]# echo "*" #print * *
[root@centos7rzc ~]# echo D* #显示以D开头的文件或目录 Desktop Documents Downloads [root@centos7rzc ~]# echo *s #显示以s结尾的文件或目录 Documents Downloads Pictures Templates Videos [root@centos7rzc ~]# echo [[:upper:]]* #显示以大写字母开头的文件或目录 Desktop Documents Downloads Music Pictures Public Templates Videos
[root@centos7rzc ~]# echo ~ #~扩展 /root
[root@centos7rzc ~]# echo $((3+2)) #算数扩展 5 [root@centos7rzc ~]# echo $(((3+2)*5)) 25 [root@centos7rzc ~]#
[root@centos7rzc ~]# echo $((3**2)) #**取幂 9 [root@centos7rzc ~]# echo $((3**4)) 81
大括号扩展
[root@centos7rzc ~]# echo A{1,2,3} A1 A2 A3
[root@centos7rzc testdir]# mkdir {2014..2015}-{01..05} [root@centos7rzc testdir]# ls 2014-01 2014-02 2014-03 2014-04 2014-05 2015-01 2015-02 2015-03 2015-04 2015-05
变量扩展
[root@centos7rzc testdir]# echo $HOSTNAME centos7rzc.jacen
命令替换
[root@centos7rzc testdir]# echo $(ls) 2014-01 2014-02 2014-03 2014-04 2014-05 2015-01 2015-02 2015-03 2015-04 2015-05 [root@centos7rzc testdir]# echo `ls` 2014-01 2014-02 2014-03 2014-04 2014-05 2015-01 2015-02 2015-03 2015-04 2015-05
[root@centos7rzc testdir]# ls -l $(which file) -rwxr-xr-x. 1 root root 19752 Jun 9 2014 /usr/bin/file
双引号
[root@centos7rzc testdir]# echo this is a word! #多个空格被识别为1个 this is a word! [root@centos7rzc testdir]# echo "this is a word! " #多个空格解决方案 this is a word!
[root@centos7rzc testdir]# echo "$(ls -l)" #请与下面的内容对比 total 40 drwxr-xr-x. 2 root root 4096 Mar 5 03:38 2014-01 drwxr-xr-x. 2 root root 4096 Mar 5 03:38 2014-02 drwxr-xr-x. 2 root root 4096 Mar 5 03:38 2014-03 drwxr-xr-x. 2 root root 4096 Mar 5 03:38 2014-04 drwxr-xr-x. 2 root root 4096 Mar 5 03:38 2014-05 drwxr-xr-x. 2 root root 4096 Mar 5 03:38 2015-01 drwxr-xr-x. 2 root root 4096 Mar 5 03:38 2015-02 drwxr-xr-x. 2 root root 4096 Mar 5 03:38 2015-03 drwxr-xr-x. 2 root root 4096 Mar 5 03:38 2015-04 drwxr-xr-x. 2 root root 4096 Mar 5 03:38 2015-05 [root@centos7rzc testdir]# echo $(ls -l) #换行符被识别为分隔符 total 40 drwxr-xr-x. 2 root root 4096 Mar 5 03:38 2014-01 drwxr-xr-x. 2 root root 4096 Mar 5 03:38 2014-02 drwxr-xr-x. 2 root root 4096 Mar 5 03:38 2014-03 drwxr-xr-x. 2 root root 4096 Mar 5 03:38 2014-04 drwxr-xr-x. 2 root root 4096 Mar 5 03:38 2014-05 drwxr-xr-x. 2 root root 4096 Mar 5 03:38 2015-01 drwxr-xr-x. 2 root root 4096 Mar 5 03:38 2015-02 drwxr-xr-x. 2 root root 4096 Mar 5 03:38 2015-03 drwxr-xr-x. 2 root root 4096 Mar 5 03:38 2015-04 drwxr-xr-x. 2 root root 4096 Mar 5 03:38 2015-05
单引号
[root@centos7rzc testdir]# echo $USER root [root@centos7rzc testdir]# echo ‘$USER‘ #单引号内不进行变量扩展 $USER
转移字符
[root@centos7rzc testdir]# echo \$ \\ \t \n $ \ t n [root@centos7rzc testdir]# echo -e "\$ \\ \t \n" $ \ [root@centos7rzc testdir]# [root@centos7rzc testdir]# echo "\$ \\ "$‘\t \n‘#使用$可以起到-e的作用 $ \ [root@centos7rzc testdir]#
\a Bell (“Alert” - causes the computer to beep)
\b Backspace
\n Newline. On Unix-like systems, this
produces a linefeed.
\r Carriage return
\t Tab
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。