Extended Globbing

Much like the order of operations in mathematics, Bash evaluates these shell expansions in a specific order.

  1. Brace Expansion

    • {1..8}

  2. Tilde Expansion

    • ~/

  3. Parameter Expansion

    • $USER , $USERID

  4. Variable Expansion

    • $(who | tail -n10 | awk '{print $2}')

  5. Arithmetic Expansion & Command Substitution (left to right)

    • $(($USERID + 12 ))

  6. Word Splitting

  7. Filename Expansion

    • .*

  8. Quote Removal

    • "$USER"

ENABLING EXTENDED GLOBBING

shopt -s extglob

LEARNNN

cd PracticeFiles
touch Logfile_{0{0..9},1{1..2}}_{1..30}_202{0..2}.{txt,log}.{csv,xlsx,pdf}; touch Logfile_{0{0..9},1{1..2}}_{1..30}_202{0..2}.{txt,log}; touch Backup_{0{0..9},1{1..2}}_{1..30}_202{0..2}.{txt,log}.{csv,xlsx,pdf}; touch Backup_{0{0..9},1{1..2}}_{1..30}_202{0..2}.{txt,log}; touch corgi.{png,jpg,raw
mkdir {Logs,Backups}
#Be sure to enable extended globbing before continuing:
shopt -s extglob
#Use the ls command to list the files that match this pattern
ls @(Logfile)*@(@(.log|.txt)@(.csv|.xlsx|.pdf))
#Now that we’ve matched the proper files, we can move them to the Logs directory using them mv command.
mv @(Logfile)*@(@(.log|.txt)@(.csv|.xlsx|.pdf)) Logs

Last updated