Monday, December 21, 2009

Bash, and matching dot-files with wildcards

Live and learn! For years, I've used Linux, and never known how to get * to match all files (by "all" I mean including files that start with a dot).

For example:

# du -ks * | sort -n
4 courierimapsubscribed
4 tmp
20 new
148 courierimapuiddb
348 courierimapkeywords
163356 cur
# du -ks .* | sort -n
388 .Trash
456 .Drafts
664 .ldap
58844 .2007
77644 .Sent
97852 .2008
450348 .
450364 ..



It finally irritated me enough to find out:


# shopt -s dotglob
# du -ks * | sort -n
4 courierimapsubscribed
4 tmp
20 new
148 courierimapuiddb
348 courierimapkeywords
388 .Trash
456 .Drafts
664 .ldap
58844 .2007
77644 .Sent
97852 .2008
163356 cur



So: shopt -s dotglob to turn it on, and shopt -u dotglob to turn it off again.

No comments:

Post a Comment