13,420
edits
Changes
→Filename Expansion
As you can see, the last Linux command you issued requires the <u>least</u> amount of keystrokes (more efficient).
[[Image:globbing-demo.png|thumb|right|400px|'''Globbing''' is the process of expanding filenames as separate arguments that match an argument that uses a '''wildcard symbol''' (such as '''*''').]]
'''File globbing''' is a feature provided by the UNIX/Linux shell to represent multiple filenames by using special characters called wildcards with a single file name. A wildcard is essentially a symbol which may be used to substitute for one or more characters. Therefore, we can use wildcards for generating the appropriate combination of file names as per our requirement.<br>Reference: https://www.linuxnix.com/10-file-globbing-examples-linux-unix/
As shown in the diagram on the right, when the ls command is issued with a filename expansion symbol (like *), the Bash shell searches for files that match the symbol (in this case all filenames that end with the extension ".txt") and expands the argument using the wildcards with those filenames as separate arguments. You do not see this happen in the shell, it is a process that occurs "behind the scenes".
Below are the most common Filename Expansion symbols and how they are used for filename expansion:
<table cellpadding="5"><tr><th style="border-bottom: 1px solid black;">Filename Expansion Symbol</th><th style="border-bottom: 1px solid black;text-align:left;">Purpose</th></tr><tr><td>'''*'''</td><td>Asterisk (*) to represent '''0 or more characters'''</td></tr><tr><td>'''?'''</td><td>Question mark (?) to represent '''exactly one character (any character)'''</td></tr><tr><td>'''[ ]'''</td><td>Square brackets ([ ]) to represent and match for the '''character enclosed within the square brackets'''.<br>It represents ONLY ONE character - '''its like a Question Mark (?) but with restrictions'''</td></tr><tr><td>'''[! ]'''</td><td>Square brackets containing an exclamation mark immediately after the open square bracket ([! ])<br>to represent and match and '''OPPOSITE''' character for the character enclosed within the square brackets.</td></tr></table>