WriteBash - Working mechanism of wildcard characters, we call it pathname expansion. So how does the this expansion in Linux work?
Example of pathname expansion
Let’s try a simple example with the ls command, simply listing the current directory.
linuxmint Pictures # ls 36845609-dragon-picture.jpg knight.jpg 481821.jpg macOS-Sierra-Wallpaper-Macbook-Wallpaper.jpg apple_icon.png mac.png bear.jpg Webcam
Now try expansion with the printing of files and folders with names beginning with
linuxmint Pictures # echo mac* macOS-Sierra-Wallpaper-Macbook-Wallpaper.jpg mac.png
Or we will try expansion with printing the files that have the
linuxmint Pictures # echo *png apple_icon.png mac.png
Or we want to print out the file names with the first capital letters.
Recommended Reading: What is the expansion in Linux?
linuxmint Pictures # echo [[:upper:]]* Webcam
Pathname expansion of hidden files
Hidden files in Linux, names start with a dot character. So what about pathname expansion with hidden files?
If you type
echo * as above, expansion does not work and hidden files are not displayed on the screen.
So we will use expansion with the start character of the hidden file, this should work.
$ echo .*
For example, we print hidden files in the
linuxmint etc # echo .* . .. .java .pwd.lock
Do you see the names
.. appears at the beginning of the result, it represents the current directory and its parent directory. This results in inaccurate results.
Now try the following command to see if the result is as an example.
linuxmint etc # echo .[!.]* .java .pwd.lock
The result is more accurate right? Explain here, the
[!.] character part is also expansion and it handles the exclusion of filenames named
ls command with the
-A option will give you the same result.
$ ls -A
You can understand more about wildcards in Linux, what is it and how does it work. This is not entirely useless, as it can help you faster in filtering information on the system.If you liked this article, then please subscribe to our YouTube Channel for more video tutorials. You can also find us on Twitter and Facebook.
If you appreciate what we share in this blog, you can support us by:
- Stay connected to: Facebook | Twitter | Google Plus | YouTube
- Subscribe email to recieve new posts from us: Sign up now.
- Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
- Become a Supporter - Make a contribution via PayPal.
- Support us by purchasing Ribbon Lite Child theme being using on this website.
We are thankful for your support.