* | Matches any characters |
? | Matches any single character |
[characters] | Matches any character that is a member of the set characters |
[!characters] | Matches any character that is not a member of the set characters |
[[:class:]] |
Matches any character that is a member of the specified class |
echo *
It might appear at first glance that we could include hidden files in an expansion by starting the pattern with a leading period, like this:
echo .*
It almost works. However, if we examine the results closely, we will see that the names . and .. will also appear in the results. Because these names refer to the current working directory and its parent directory, using this pattern will likely produce an incorrect result. We can see this if we try the following command:
ls -d .* | less
To better perform pathname expansion in this situation, we have to employ a more specific pattern
echo .[!.]*
This pattern expands into every filename that begins with only one period fol- lowed by any other characters. This will work correctly with most hidden files (though it still won't include filenames with multiple leading periods). The ls command with the -A option (“almost all”) will provide a correct listing of hid- den files.
ls -A
| Matches any alphanumeric character |
| Matches any alphabetic character |
| Matches any numeral |
| Matches any lowercase letter |
| Matches any uppercase letter |
Wildcards can be used with any command that accepts filenames as arguments
1, cp
-a --archive Copy the files and directories and all of their attributes, including ownerships and permissions. Normally, copies take on the default attributes of the user performing the copy.
-r --recursive Recursively copy directories and their contents. This option (or the -a option) is required when copying directories.
-u --update When copying files from one directory to another, only copy files that either don't exist or are newer than the existing corresponding files, in the destination directory.
cp item... directory
copies multiple items (either files or directories) into a directory.
2,mv
mv item... directory
to move one or more items from one directory to another.
3,ln
The following creates a hard link:
ln file link
The following creates a symbolic link:
ln -s item link