Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Match .dot files with the wildcard character * in Bash

# See:
# - http://wooledge.org:8000/glob
# - http://bash-hackers.org/wiki/doku.php/syntax/expansion/globs

help shopt

shopt dotglob

man bash 2>/dev/null | less -p dotglob     # navigate by pressing n or N


# cf. LSCOLORS Generator, http://geoff.greer.fm/lscolors/
# man ls
export CLICOLOR_FORCE=1
#export CLICOLOR=1
#export LSCOLORS=ExGxFxDxCxHxHxCbCeEbEb
#export LSCOLORS=GxFxCxDxBxegedabagacad      
#export LSCOLORS=gxfxcxdxbxegedabagacad     # cyan directories
export LSCOLORS="exfxcxdxbxegedabagacad"    # blue directories


ls -1aFG /
ls -1aFG ~
ls -1aFG /Users

ls -1dFG ~/* | nl | less -r

shopt -s dotglob

ls -1dFG ~/* | nl | less -r

shopt -u dotglob


# delete all files & folders in tmp directories
#shopt -s dotglob
#sudo rm -PRi /tmp/* /private/var/tmp/*
#sudo rm -PRfv /tmp/* /private/var/tmp/*
#shopt -u dotglob

Copy and rename files with wildcards (globs)

To copy files jgarner_* to Alias_*:

Dir.glob("jgarner_*") { |name| `cp #{name} #{name.sub(/jgarner_/, "Alias_")}`}

or

ruby -e 'Dir.glob("jgarner_*") { |name| `cp #{name} #{name.sub(/jgarner_/, "Alias_")}`}'