002. Linux基础二 (命令行/括号拓展、TAB、history)

时间:2020-11-07 16:56:47   收藏:0   阅读:27
1. 命令行扩展

1.1 `` 和 $()

$(CMD) OR ` CMD `

比较"" ‘‘ `` 三者的区别

结论

[root@centos7 ~]# echo "echo $HOSTNAME"
echo centos7
[root@centos7 ~]# echo ‘echo $HOSTNAME‘
echo $HOSTNAME
[root@centos7 ~]# echo `echo $HOSTNAME`
centos7
[root@centos7 ~]# echo "i‘m $(hostname)"
i‘m centos7
[root@centos7 ~]# echo "i‘am `whoami`"
i‘am root
[root@centos7 ~]# echo `hostname`-`date +%F`
centos7-2020-11-06

$( ) 和 ``

[root@centos7 ~]# touch `date +%F`.txt
[root@centos7 ~]# ll
-rw-r--r--. 1 root root    0 11月  6 22:06 2020-11-06.log
-rw-r--r--. 1 root root    0 11月  6 22:19 2020-11-06.txt
[root@centos7 ~]# ll $(echo $(date +%F).txt)
-rw-r--r--. 1 root root 0 11月  6 22:17 2020-11-06.txt
[root@centos7 ~]# ll `echo $(date +%F).txt`
-rw-r--r--. 1 root root 0 11月  6 22:17 2020-11-06.txt
[root@centos7 ~]# ll $(echo `date +%F`.txt)
-rw-r--r--. 1 root root 0 11月  6 22:17 2020-11-06.txt

2. 括号扩展:{ }

{} 可以实现打印重复字符串的简化形式

[root@centos7 ~]# echo file{1,3,4}
file1 file3 file4
[root@centos7 ~]# echo {1..10}
1 2 3 4 5 6 7 8 9 10
[root@centos7 ~]# echo {1..10..2}
1 3 5 7 9
[root@centos7 ~]# echo {000..10..2}
000 002 004 006 008 010
[root@centos7 ~]# echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z

3. 双击TAB键

4. 命令行历史 history

4.1 选项
4.2 命令历史相关环境变量
4.3 持久保存变量

以上变量可以 export 变量名="值" 形式存放在 /etc/pro?le 或 ~/.bash_pro?le

4.4 调用命令行历史
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!