INSTALLING THE TOOLS
We need three things: ack, rename, and perl. Perl comes with your system. The other two need installing.
macOS (Homebrew)
If you don't have Homebrew yet:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then install our tools:
brew install ack
brew install rename
That's it. Both tools are now available.
Linux (Debian/Ubuntu)
sudo apt update
sudo apt install ack rename
On some systems, ack is called ack-grep:
sudo apt install ack-grep
# Then use 'ack-grep' instead of 'ack' in commands
Linux (Fedora/RHEL)
sudo dnf install ack perl-rename
Note: Fedora's rename might be different. Make sure you get the Perl-based one, not the util-linux one.
Windows (WSL)
Install Windows Subsystem for Linux first, then use the Ubuntu instructions above.
Verify Installation
Check everything works:
ack --version
# Should show: ack v3.x.x
rename --version
# Should show: rename from File::Rename
perl -v
# Should show your Perl version (5.x.x)
A Note on "rename"
There are two different programs called "rename":
- Perl rename (what we want) - Uses regex patterns - Can do complex transformations - The one Homebrew and most Linux distros install
- util-linux rename (NOT what we want) - Simple string replacement only - Limited functionality
If your rename doesn't support regex, you might have the wrong one. On some systems, the Perl version is called "prename" or "perl-rename".
Creating a Practice Folder
Let's make a folder with test files to play with:
mkdir ~/regex-practice
cd ~/regex-practice
# Create some sample files
touch photo_001.jpg photo_002.jpg photo_003.jpg
touch IMG_2024_06_15.png IMG_2024_07_20.png
touch document.txt notes.txt readme.md
touch "file with spaces.txt"
touch log_error.txt log_warning.txt log_info.txt
# Add content to some files
echo "Hello World" > document.txt
echo "TODO: fix this later" > notes.txt
echo "FIXME: broken code here" >> notes.txt
echo "Error: connection failed" > log_error.txt
echo "Warning: low memory" > log_warning.txt
echo "Info: process started" > log_info.txt
You now have files to experiment with. We'll use this folder throughout the tutorial.