{} 花括号的用法

{} 花括号的用法

备份

[root@centos6 app]# touch test.log
[root@centos6 app]# ls
test.log
[root@centos6 app]# 
[root@centos6 app]# cp test.log{,.bak}
[root@centos6 app]# ls
test.log  test.log.bak
[root@centos6 app]#

连续

[root@centos6 app]# echo file{1..2}
file1 file2
[root@centos6 app]# echo file{1..10}
file1 file2 file3 file4 file5 file6 file7 file8 file9 file10
[root@centos6 app]# echo file{001..10}
file001 file002 file003 file004 file005 file006 file007 file008 file009 file010
[root@centos6 app]# 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
[root@centos6 app]# 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

倒序

[root@centos6 app]# echo {9..1}
9 8 7 6 5 4 3 2 1
[root@centos6 app]# 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
[root@centos6 app]# 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
[root@centos6 app]# 

步进

[root@centos6 app]# echo file{001..10..2}
file001 file003 file005 file007 file009
[root@centos6 app]# echo file{001..10..3}
file001 file004 file007 file010
[root@centos6 app]#
[root@centos6 app]# echo {9..1..3}
9 6 3
[root@centos6 app]# 

自由组合1(连续和非连续的)

mkdir -p /testdir/dir1/{x..y}/{a..b}
mkdir -p /testdir/dir1/{x,y}/{a,b}
mkdir -p /testdir/dir2/{x/{a..b},y}
mkdir -p /testdir/dir{3,4,5/dir{6..7}}

自由组合2(非连续的)

touch {a,d,g}.{log,txt}

效果

[root@centos7 app]$touch {a,d,g}.{log,txt}
[root@centos7 app]$ls
a.log  a.txt  d.log  d.txt  g.log  g.txt
[root@centos7 app]$

自由组合3(连续的)

touch {1..9}.{a..c}

效果

[root@centos7 app]$
[root@centos7 app]$touch {1..9}.{a..c}
[root@centos7 app]$ls
1.a  1.c  2.b  3.a  3.c  4.b  5.a  5.c  6.b  7.a  7.c  8.b  9.a  9.c
1.b  2.a  2.c  3.b  4.a  4.c  5.b  6.a  6.c  7.b  8.a  8.c  9.b
[root@centos7 app]$ll
total 0
-rw-r--r--. 1 root root 0 Nov 17 11:22 1.a
-rw-r--r--. 1 root root 0 Nov 17 11:22 1.b
-rw-r--r--. 1 root root 0 Nov 17 11:22 1.c
-rw-r--r--. 1 root root 0 Nov 17 11:22 2.a
-rw-r--r--. 1 root root 0 Nov 17 11:22 2.b
-rw-r--r--. 1 root root 0 Nov 17 11:22 2.c
-rw-r--r--. 1 root root 0 Nov 17 11:22 3.a
-rw-r--r--. 1 root root 0 Nov 17 11:22 3.b
-rw-r--r--. 1 root root 0 Nov 17 11:22 3.c
-rw-r--r--. 1 root root 0 Nov 17 11:22 4.a
-rw-r--r--. 1 root root 0 Nov 17 11:22 4.b
-rw-r--r--. 1 root root 0 Nov 17 11:22 4.c
-rw-r--r--. 1 root root 0 Nov 17 11:22 5.a
-rw-r--r--. 1 root root 0 Nov 17 11:22 5.b
-rw-r--r--. 1 root root 0 Nov 17 11:22 5.c
-rw-r--r--. 1 root root 0 Nov 17 11:22 6.a
-rw-r--r--. 1 root root 0 Nov 17 11:22 6.b
-rw-r--r--. 1 root root 0 Nov 17 11:22 6.c
-rw-r--r--. 1 root root 0 Nov 17 11:22 7.a
-rw-r--r--. 1 root root 0 Nov 17 11:22 7.b
-rw-r--r--. 1 root root 0 Nov 17 11:22 7.c
-rw-r--r--. 1 root root 0 Nov 17 11:22 8.a
-rw-r--r--. 1 root root 0 Nov 17 11:22 8.b
-rw-r--r--. 1 root root 0 Nov 17 11:22 8.c
-rw-r--r--. 1 root root 0 Nov 17 11:22 9.a
-rw-r--r--. 1 root root 0 Nov 17 11:22 9.b
-rw-r--r--. 1 root root 0 Nov 17 11:22 9.c
[root@centos7 app]$

猜你喜欢

转载自www.cnblogs.com/shichangming/p/10010549.html