You can use some wildcard characters (metacharacter wildcards) to match part of a file or a directory name.
-
*: match any number of characters.
$ cd ${user.home}/folder/
$ ls fold*
folder1:
folder2:
-
?: match one occurrence of a character.
$ cd ${user.home}/folder/
$ ls f??der?
folder1:
folder2:
-
[...]: define one occurrence, a set, or a range of characters.
$ cd ${user.home}/folder/
$ ls f[a-z]*[0-9]
folder1:
folder2:
You can also use curly braces (
{}) to expand a set of characters to match part of a file or a directory name.
$ touch file{1,2,3}
$ ls file*
file1 file2 file3
$ touch file-{a..c}-{1,2,3}
$ ls file-*
file-a-1 file-a-2 file-a-3 file-b-1 file-b-2 file-b-3 file-c-1 file-c-2 file-c-3
You can use the exclamation character (
!) to exclude a pattern:
$ ls file-[!a-b]-[!1-2]
file-c-3