A very useful feature in the bash operating environment is wildcards.
Some commonly used wildcards are listed below, as shown in the following table
symbol | significance |
* | Wild character, representing any character from 0 to infinity |
? | Wild character, which means there must be an arbitrary character |
[] | means that there must be a character within square brackets. For example: [abcd] means there must be a character, which may be any of the four a, b, c, d |
[-] | If there is a minus sign in square brackets, it represents all characters in the coding order. For example: [0-9] represents all numbers between 0 and 9, because the language encoding of numbers is continuous |
[^] | If the first character in the brackets is an exponential symbol (^), it means reverse selection, for example: [^abcd] means that there must be a character, as long as it is not one of a, b, c, and d. |
Example 1: Find the file name starting with cron under /etc/
[root@bogon ~]# ll -d /etc/cron* drwxr-xr-x. 2 root root 4096 Apr 25 09:04 /etc/cron.d drwxr-xr-x. 2 root root 4096 Apr 25 09:05 /etc/cron.daily ....
Example 2: Find out the file name under /etc/ that is exactly five-letter file name
[root@bogon ~]# ll -d /etc/????? drwxr-x---. 2 root root 4096 Apr 25 09:04 /etc/audit drwxr-xr-x. 2 root root 4096 Apr 25 08:59 /etc/avahi drwxr-xr-x. 2 root root 4096 Feb 21 2013 /etc/blkid ......
Example 3: Find the file names with numbers in the file names under /etc/
[root@bogon ~]# ll -d /etc/*[0-9]* drwxr-xr-x. 4 root root 4096 Apr 25 08:58 /etc/dbus-1 -rw-r--r--. 1 root root 5139 Apr 17 2012 /etc/DIR_COLORS.256color drwxr-xr-x. 3 root root 4096 Apr 25 08:59 /etc/gnome-vfs-2.0 ......
Example 4: Find the file name under /etc/ whose file name starts with a lowercase letter
[root@bogon ~]# ll -d /etc/[a-z]* drwxr-xr-x. 3 root root 4096 Apr 25 08:59 /etc/abrt drwxr-xr-x. 4 root root 4096 Apr 25 09:04 /etc/acpi -rw-r--r--. 1 root root 44 Aug 14 03:01 /etc/adjtime ...
Example 5: Copy the file name starting with a lowercase letter under the /etc/ directory to the /tmp directory
[root@bogon ~]# cp -a /etc/[a-z]* /tmp