Brace Expansion
Learn how brace expansion generates multiple arguments from a compact pattern.
{a,b,c} expands to a b c. Range expansion uses two dots: {1..5} expands to 1 2 3 4 5. You can combine these with surrounding text to generate complex patterns.# List expansion
touch file_{a,b,c}.txt # Creates file_a.txt, file_b.txt, file_c.txt
# Range expansion
touch report_{1..5}.md # Creates report_1.md through report_5.md
# Combine with paths
mkdir -p src/{components,utils,hooks} # Three subdirectories in one commandtouch, mkdir, cp, echo, anything. It's purely a text substitution: the shell replaces the brace expression with the expanded list, then runs the resulting command.You can preview what brace expansion produces by using echo. Running echo file_{a,b,c}.txt prints "file_a.txt file_b.txt file_c.txt" without creating anything. It's a great way to test your pattern before committing to it.
Our terminal simulator does not support brace expansion natively. In a real terminal, you'd use these patterns directly. For practice here, we'll create files individually with touch to build the same muscle memory.
Brace expansion is not available in Command Prompt or PowerShell natively. PowerShell uses different approaches like 1..5 | ForEach-Object { New-Item "file_$_.txt" }. In WSL or Git Bash on Windows, brace expansion works just like on Linux.
touch to create three files: file_a.txt, file_b.txt, and file_c.txt. In a real terminal, you'd type touch file_{a,b,c}.txt to do this in one command.touch file_a.txt
touch file_b.txt
touch file_c.txt