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:
1. Open Terminal.
2. Navigate to the directory containing your files.
3. Create a new script file: nano bulk_rename.sh
4. Paste the above code into the file and save it.
5. Make the script executable: chmod +x bulk_rename.sh
6. Run the script: ./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:
1. Install Homebrew if you haven't already:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
2. Install the rename
command:
brew install rename
3. Use the 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.
1. Open Script Editor.
2. Paste the following AppleScript code:
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
3. Save the script as an application.
4. Select the files in Finder and run the application.