Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Bulk renaming files can be a tedious and time-consuming task if done manually, especially when dealing with a large number of files. Fortunately, macOS provides powerful tools to automate this process using the Terminal. This article will guide you through different methods to bulk rename files on macOS, making your workflow more efficient and saving you valuable time.
Examples:
mv
Command with a LoopOne of the simplest ways to bulk rename files is by using a loop in the Terminal. Here’s an example of how to rename all .txt
files in a directory by adding a prefix "new_".
#!/bin/bash
for file in *.txt; do
mv "$file" "new_$file"
done
To run this script:
nano bulk_rename.sh
chmod +x bulk_rename.sh
./bulk_rename.sh
rename
CommandThe rename
command is not installed by default on macOS, but it can be installed using Homebrew. Here’s how to install and use it:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
rename
command:
brew install rename
rename
command to bulk rename files. For example, to replace spaces with underscores in all .txt
files:
rename 's/ /_/g' *.txt
find
and xargs
For more complex renaming tasks, you can combine find
and xargs
. Here’s an example of renaming all .jpg
files to .jpeg
:
find . -name "*.jpg" -print0 | xargs -0 -I {} mv {} {}.jpeg
For users who prefer a GUI-based approach, AppleScript can be used to create a simple application for bulk renaming files.
tell application "Finder"
set theFiles to selection
repeat with aFile in theFiles
set name of aFile to "new_" & (get name of aFile)
end repeat
end tell