命令行展开

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了命令行展开相关的知识,希望对你有一定的参考价值。

[[email protected] tmp]# mkdir {a,b}_{c,d}
[[email protected] tmp]# ll
total 16
drwxr-xr-x 2 root root 4096 Feb  7 23:51 a_c
drwxr-xr-x 2 root root 4096 Feb  7 23:51 a_d
drwxr-xr-x 2 root root 4096 Feb  7 23:51 b_c
drwxr-xr-x 2 root root 4096 Feb  7 23:51 b_d
[[email protected] mylinux]# mkdir -p {bin,boot/grub,dev,etc/{rc.d/init.d,sysconfig/network-scripts},lib/modules,lib64,proc,sbin,sys,tmp,usr/local/{bin,sbin},var/{lock,log,run}}
[[email protected] mylinux]# tree -a
.
|-- bin
|-- boot
|   `-- grub
|-- dev
|-- etc
|   |-- rc.d
|   |   `-- init.d
|   `-- sysconfig
|       `-- network-scripts
|-- lib
|   `-- modules
|-- lib64
|-- proc
|-- sbin
|-- sys
|-- tmp
|-- usr
|   `-- local
|       |-- bin
|       `-- sbin
`-- var
    |-- lock
    |-- log
    `-- run
[[email protected] mylinux]# alias boot=‘who -b‘
[[email protected] mylinux]# boot
         system boot  Feb  6 11:03
[[email protected] ~]# a=`ls -l`
[[email protected] ~]# echo $a
总用量 4 -rw-------. 1 root root 964 2月 8 13:23 anaconda-ks.cfg
[[email protected] ~]# a=$(w)
[[email protected] ~]# echo $a
13:50:13 up 21 min, 2 users, load average: 1.10, 0.57, 0.26 USER TTY FROM [email protected] IDLE JCPU PCPU WHAT root tty1 13:42 3:49 53.34s 53.17s /usr/bin/python /bin/yum update -y root pts/0 192.168.88.110 13:49 5.00s 0.04s 0.02s w
[[email protected] ~]# echo ${a}
13:50:13 up 21 min, 2 users, load average: 1.10, 0.57, 0.26 USER TTY FROM [email protected] IDLE JCPU PCPU WHAT root tty1 13:42 3:49 53.34s 53.17s /usr/bin/python /bin/yum update -y root pts/0 192.168.88.110 13:49 5.00s 0.04s 0.02s w
#显示/var目录下所有以l开头,以一个小写字母结尾,且中间至少出现一位数字(可以有其它字符)的文件或目录
[[email protected] var]# ls -d l*[[:digit:]]*[[:lower:]]
l0001a  l222ccc
#显示/etc目录下,以任意一个数字开头,且以非数字结尾的文件或目录
[[email protected] etc]# touch 4ccd
[[email protected] etc]# mkdir 5aj
[[email protected] etc]# ls -d /etc/[0-9]*[^0-9]
/etc/4ccd  /etc/5aj
#显示/etc目录下,以非字母开头,后面跟了一个字母以及其它任意长度任意字符的文件或目录
[[email protected] etc]# touch 6Aj
[[email protected] etc]# mkdir 7JD
[[email protected] etc]# ls -d /etc/[^a-zA-Z][a-zA-Z]*
/etc/4ccd  /etc/5aj  /etc/6Aj  /etc/7JD
#在/tmp目录下创建以tfile开头,后跟当前日期和时间的文件,文件名形如:tfile–2016–05–27–09–32–22
[[email protected] tmp]# touch tfile-$(date +%Y-%m-%d-%H-%M-%S)
[[email protected] tmp]# ll
总用量 0
-rw-r--r--. 1 root root 0 2月   8 14:54 tfile-2017-02-08-14-54-14
#复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest1目录中
[[email protected] tmp]# cd /etc
[[email protected] etc]# mkdir /tmp/mytest1
[[email protected] etc]# cp -rv p*[^0-9]
"pam.d" -> "python/pam.d"
"pam.d/config-util" -> "python/pam.d/config-util"
"pam.d/other" -> "python/pam.d/other"
"pam.d/chfn" -> "python/pam.d/chfn"
"pam.d/chsh" -> "python/pam.d/chsh"
"pam.d/login" -> "python/pam.d/login"
"pam.d/remote" -> "python/pam.d/remote"
"pam.d/runuser" -> "python/pam.d/runuser"
"pam.d/runuser-l" -> "python/pam.d/runuser-l"
"pam.d/su" -> "python/pam.d/su"
"pam.d/su-l" -> "python/pam.d/su-l"
"pam.d/systemd-user" -> "python/pam.d/systemd-user"
"pam.d/polkit-1" -> "python/pam.d/polkit-1"
"pam.d/crond" -> "python/pam.d/crond"
"pam.d/ppp" -> "python/pam.d/ppp"
"pam.d/vlock" -> "python/pam.d/vlock"
"pam.d/smtp.postfix" -> "python/pam.d/smtp.postfix"
"pam.d/smtp" -> "python/pam.d/smtp"
"pam.d/sshd" -> "python/pam.d/sshd"
"pam.d/passwd" -> "python/pam.d/passwd"
"pam.d/sudo" -> "python/pam.d/sudo"
"pam.d/sudo-i" -> "python/pam.d/sudo-i"
"pam.d/system-auth-ac" -> "python/pam.d/system-auth-ac"
"pam.d/system-auth" -> "python/pam.d/system-auth"
"pam.d/postlogin-ac" -> "python/pam.d/postlogin-ac"
"pam.d/postlogin" -> "python/pam.d/postlogin"
"pam.d/password-auth-ac" -> "python/pam.d/password-auth-ac"
"pam.d/password-auth" -> "python/pam.d/password-auth"
"pam.d/fingerprint-auth-ac" -> "python/pam.d/fingerprint-auth-ac"
"pam.d/fingerprint-auth" -> "python/pam.d/fingerprint-auth"
"pam.d/smartcard-auth-ac" -> "python/pam.d/smartcard-auth-ac"
"pam.d/smartcard-auth" -> "python/pam.d/smartcard-auth"
"passwd" -> "python/passwd"
"passwd-" -> "python/passwd-"
"pki" -> "python/pki"
"pki/rpm-gpg" -> "python/pki/rpm-gpg"
"pki/rpm-gpg/RPM-GPG-KEY-CentOS-7" -> "python/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7"
"pki/rpm-gpg/RPM-GPG-KEY-CentOS-Debug-7" -> "python/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Debug-7"
"pki/rpm-gpg/RPM-GPG-KEY-CentOS-Testing-7" -> "python/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Testing-7"
"pki/tls" -> "python/pki/tls"
"pki/tls/certs" -> "python/pki/tls/certs"
"pki/tls/certs/ca-bundle.crt" -> "python/pki/tls/certs/ca-bundle.crt"
"pki/tls/certs/ca-bundle.trust.crt" -> "python/pki/tls/certs/ca-bundle.trust.crt"
"pki/tls/certs/Makefile" -> "python/pki/tls/certs/Makefile"
"pki/tls/certs/make-dummy-cert" -> "python/pki/tls/certs/make-dummy-cert"
"pki/tls/certs/renew-dummy-cert" -> "python/pki/tls/certs/renew-dummy-cert"
"pki/tls/misc" -> "python/pki/tls/misc"
"pki/tls/misc/CA" -> "python/pki/tls/misc/CA"
"pki/tls/misc/c_hash" -> "python/pki/tls/misc/c_hash"
"pki/tls/misc/c_info" -> "python/pki/tls/misc/c_info"
"pki/tls/misc/c_issuer" -> "python/pki/tls/misc/c_issuer"
"pki/tls/misc/c_name" -> "python/pki/tls/misc/c_name"
"pki/tls/openssl.cnf" -> "python/pki/tls/openssl.cnf"
"pki/tls/private" -> "python/pki/tls/private"
"pki/tls/cert.pem" -> "python/pki/tls/cert.pem"
"pki/ca-trust" -> "python/pki/ca-trust"
"pki/ca-trust/README" -> "python/pki/ca-trust/README"
"pki/ca-trust/ca-legacy.conf" -> "python/pki/ca-trust/ca-legacy.conf"
"pki/ca-trust/extracted" -> "python/pki/ca-trust/extracted"
"pki/ca-trust/extracted/README" -> "python/pki/ca-trust/extracted/README"
"pki/ca-trust/extracted/java" -> "python/pki/ca-trust/extracted/java"
"pki/ca-trust/extracted/java/README" -> "python/pki/ca-trust/extracted/java/README"
"pki/ca-trust/extracted/java/cacerts" -> "python/pki/ca-trust/extracted/java/cacerts"
"pki/ca-trust/extracted/openssl" -> "python/pki/ca-trust/extracted/openssl"
"pki/ca-trust/extracted/openssl/README" -> "python/pki/ca-trust/extracted/openssl/README"
"pki/ca-trust/extracted/openssl/ca-bundle.trust.crt" -> "python/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt"
"pki/ca-trust/extracted/pem" -> "python/pki/ca-trust/extracted/pem"
"pki/ca-trust/extracted/pem/README" -> "python/pki/ca-trust/extracted/pem/README"
"pki/ca-trust/extracted/pem/tls-ca-bundle.pem" -> "python/pki/ca-trust/extracted/pem/tls-ca-bundle.pem"
"pki/ca-trust/extracted/pem/email-ca-bundle.pem" -> "python/pki/ca-trust/extracted/pem/email-ca-bundle.pem"
"pki/ca-trust/extracted/pem/objsign-ca-bundle.pem" -> "python/pki/ca-trust/extracted/pem/objsign-ca-bundle.pem"
"pki/ca-trust/source" -> "python/pki/ca-trust/source"
"pki/ca-trust/source/README" -> "python/pki/ca-trust/source/README"
"pki/ca-trust/source/anchors" -> "python/pki/ca-trust/source/anchors"
"pki/ca-trust/source/blacklist" -> "python/pki/ca-trust/source/blacklist"
"pki/ca-trust/source/ca-bundle.legacy.crt" -> "python/pki/ca-trust/source/ca-bundle.legacy.crt"
"pki/java" -> "python/pki/java"
"pki/java/cacerts" -> "python/pki/java/cacerts"
"pki/nssdb" -> "python/pki/nssdb"
"pki/nssdb/cert8.db" -> "python/pki/nssdb/cert8.db"
"pki/nssdb/cert9.db" -> "python/pki/nssdb/cert9.db"
"pki/nssdb/key3.db" -> "python/pki/nssdb/key3.db"
"pki/nssdb/key4.db" -> "python/pki/nssdb/key4.db"
"pki/nssdb/pkcs11.txt" -> "python/pki/nssdb/pkcs11.txt"
"pki/nssdb/secmod.db" -> "python/pki/nssdb/secmod.db"
"pki/CA" -> "python/pki/CA"
"pki/CA/certs" -> "python/pki/CA/certs"
"pki/CA/crl" -> "python/pki/CA/crl"
"pki/CA/newcerts" -> "python/pki/CA/newcerts"
"pki/CA/private" -> "python/pki/CA/private"
"pki/rsyslog" -> "python/pki/rsyslog"
"plymouth" -> "python/plymouth"
"plymouth/plymouthd.conf" -> "python/plymouth/plymouthd.conf"
"pm" -> "python/pm"
"pm/config.d" -> "python/pm/config.d"
"pm/power.d" -> "python/pm/power.d"
"pm/sleep.d" -> "python/pm/sleep.d"
"popt.d" -> "python/popt.d"
"postfix" -> "python/postfix"
"postfix/access" -> "python/postfix/access"
"postfix/canonical" -> "python/postfix/canonical"
"postfix/generic" -> "python/postfix/generic"
"postfix/header_checks" -> "python/postfix/header_checks"
"postfix/main.cf" -> "python/postfix/main.cf"
"postfix/master.cf" -> "python/postfix/master.cf"
"postfix/relocated" -> "python/postfix/relocated"
"postfix/transport" -> "python/postfix/transport"
"postfix/virtual" -> "python/postfix/virtual"
"ppp" -> "python/ppp"
"ppp/ip-down" -> "python/ppp/ip-down"
"ppp/ip-down.ipv6to4" -> "python/ppp/ip-down.ipv6to4"
"ppp/ip-up" -> "python/ppp/ip-up"
"ppp/ip-up.ipv6to4" -> "python/ppp/ip-up.ipv6to4"
"ppp/ipv6-down" -> "python/ppp/ipv6-down"
"ppp/ipv6-up" -> "python/ppp/ipv6-up"
"ppp/peers" -> "python/ppp/peers"
"ppp/chap-secrets" -> "python/ppp/chap-secrets"
"ppp/eaptls-client" -> "python/ppp/eaptls-client"
"ppp/eaptls-server" -> "python/ppp/eaptls-server"
"ppp/options" -> "python/ppp/options"
"ppp/pap-secrets" -> "python/ppp/pap-secrets"
"prelink.conf.d" -> "python/prelink.conf.d"
"prelink.conf.d/nss-softokn-prelink.conf" -> "python/prelink.conf.d/nss-softokn-prelink.conf"
"prelink.conf.d/fipscheck.conf" -> "python/prelink.conf.d/fipscheck.conf"
"prelink.conf.d/grub2.conf" -> "python/prelink.conf.d/grub2.conf"
"printcap" -> "python/printcap"
"profile" -> "python/profile"
"profile.d" -> "python/profile.d"
"profile.d/colorgrep.csh" -> "python/profile.d/colorgrep.csh"
"profile.d/colorgrep.sh" -> "python/profile.d/colorgrep.sh"
"profile.d/which2.csh" -> "python/profile.d/which2.csh"
"profile.d/which2.sh" -> "python/profile.d/which2.sh"
"profile.d/less.csh" -> "python/profile.d/less.csh"
"profile.d/less.sh" -> "python/profile.d/less.sh"
"profile.d/colorls.csh" -> "python/profile.d/colorls.csh"
"profile.d/colorls.sh" -> "python/profile.d/colorls.sh"
"profile.d/256term.csh" -> "python/profile.d/256term.csh"
"profile.d/256term.sh" -> "python/profile.d/256term.sh"
"profile.d/lang.csh" -> "python/profile.d/lang.csh"
"profile.d/lang.sh" -> "python/profile.d/lang.sh"
"protocols" -> "python/protocols"


以上是关于命令行展开的主要内容,如果未能解决你的问题,请参考以下文章

展开命令行及脚本安全和set

命令行展开

bash的工作特性之命令执行状态返回值和命令行展开所涉及的内容及其示例演示。

1.4 Bash的命令行展开和Bash环境的配置

命令行展开

Linux命令之bash的基础特性(命令历史命令补全路径补全命令行展开。)