Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In shell scripting, what does .[!.]* mean?

A command that prints a list of files and folders in the current directory along with their total sizes is du -sh *. That command alone doesn't, however, list hidden files or folders. I found a solution for a command that does correctly list the hidden files and folders along with the rest: du -sh .[!.]* *. Although it works perfectly, the solution was provided as-is, without any explanation.

What is the meaning of .[!.]*, exactly? How does it work?

like image 930
sig_seg_v Avatar asked Dec 08 '16 07:12

sig_seg_v


2 Answers

It's a globbing pattern that basically tells bash to find all files starting with a ., followed by any character but a .and containing any character after that.

See this page for a great explanation of bash globbing patterns.

like image 200
tgo Avatar answered Oct 22 '22 21:10

tgo


. - match a ., prefix of hidden file

[!.] - match any character, as long as it is not a ., see ref

* - any number of characters

so this pattern means match files starts with . but not ..

like image 29
georgexsh Avatar answered Oct 22 '22 21:10

georgexsh