To move files with duplicate names while keeping both copies, give each incoming file an unused destination name before moving it. This guide builds a Mac shortcut that adds numbered suffixes, using disposable text files to demonstrate the result.
The task is moving ordinary files from one local folder into another that may already contain matching names. The destination’s existing files stay in place; incoming files receive names such as notes (2).txt. Keeping both means retaining both files in the destination after the move—the incoming file no longer remains in its source folder.
What does Apple document about keeping both files?
Apple documents support for running shell scripts directly inside Shortcuts. Its public Shortcuts pages cited here do not specify a Keep Both collision policy for the Move File action. Rather than depend on an undocumented setting, this workflow makes the naming decision explicitly in Run Shell Script. Apple describes the scripting capability in Meet Shortcuts for macOS.
The underlying macOS command has a narrower documented behavior: mv -n does not overwrite an existing file. It does not generate a new name. Consequently, this shortcut needs both a filename-selection loop and the no-overwrite option. These are separate responsibilities, as shown in Apple’s published mv(1) manual source.
Finder folder merging also has limits. Apple says Merge appears only when one folder contains items absent from the other; folders containing different versions of identically named files offer Stop or Replace. Folder merging therefore does not provide the numbered-file behavior needed here. See Organize files in folders on Mac.
Prepare a disposable duplicate-name example
Use this example with two folders on the same local disk. It handles ordinary, non-hidden files directly inside the source folder. It does not recursively process subfolders, move aliases or symbolic links, or merge packages. Run one instance at a time, with neither folder being changed by another process.
The shortcut requires Run Shell Script to be available and runnable on your Mac. If that action cannot run in your setup, use the Finder procedure later in this article. The examples below require no additional software.
Open Terminal and paste this complete setup command. It creates a new Desktop folder containing only synthetic text. If Shortcuts-name-demo already exists, the command stops instead of reusing its contents.
/bin/bash <<'BASH'
set -e
root="$HOME/Desktop/Shortcuts-name-demo"
/bin/mkdir "$root"
/bin/mkdir "$root/Incoming" "$root/Collected"
printf '%s\n' 'Incoming synthetic notes.' > "$root/Incoming/notes.txt"
printf '%s\n' 'Existing synthetic notes.' > "$root/Collected/notes.txt"
printf '%s\n' 'Earlier synthetic second copy.' > "$root/Collected/notes (2).txt"
printf '%s\n' 'Synthetic readme.' > "$root/Incoming/readme.txt"
printf 'Example folder: %s\n' "$root"
BASH
The collision is deliberate: the destination already contains both notes.txt and notes (2).txt. A shortcut that merely appends (2) would encounter another collision. The useful decision rule is to test successive candidates until a name is available.
For easier inspection, enable Show all filename extensions under Finder > Settings > Advanced. Apple explains that hiding an extension changes its display, while changing the extension itself can affect which app opens the file. Keep .txt intact in this example. See Show or hide filename extensions on Mac.
Build the shortcut with explicit collision handling
Create a shortcut using the add button in Shortcuts and name it Move Files and Keep Both. Find Run Shell Script in the action library and add it. Apple documents creating shortcuts and adding actions in Create a custom shortcut on Mac.
Set the action’s shell to /bin/bash, then replace its example script with the complete program below. This version reads its two folder paths from variables in the script. It does not consume shortcut input, selected Finder items, or standard input, so the input-passing setting is immaterial.
set -e
shopt -s nullglob
src_dir="$HOME/Desktop/Shortcuts-name-demo/Incoming"
dst_dir="$HOME/Desktop/Shortcuts-name-demo/Collected"
fail() {
printf '%s\n' "$1" >&2
exit 1
}
[[ -d "$src_dir" ]] || fail "Source folder does not exist."
[[ -d "$dst_dir" ]] || fail "Destination folder does not exist."
src_dir=$(cd "$src_dir" && pwd -P)
dst_dir=$(cd "$dst_dir" && pwd -P)
[[ "$src_dir" != "$dst_dir" ]] || fail "Choose different folders."
moved=0
for src in "$src_dir"/*; do
if [[ -L "$src" || ! -f "$src" ]]; then
printf 'Skipped non-regular item: %s\n' "$src" >&2
continue
fi
name=${src##*/}
stem=$name
ext=
if [[ "$name" == *.* && "$name" != .* && "$name" != *. ]]; then
stem=${name%.*}
ext=.${name##*.}
fi
target="$dst_dir/$name"
number=2
while [[ -e "$target" || -L "$target" ]]; do
target="$dst_dir/$stem ($number)$ext"
number=$((number + 1))
done
/bin/mv -n "$src" "$target" || fail "Move failed: $src"
if [[ -e "$src" || -L "$src" || ! -f "$target" ]]; then
fail "Move was not completed as expected: $src"
fi
moved=$((moved + 1))
printf 'Moved: %s -> %s\n' "$name" "${target##*/}"
done
printf 'Completed: %s file(s) moved.\n' "$moved"
Add Quick Look after the script action to inspect its report. Apple specifically recommends inserting Quick Look while testing to see what content flows between actions. See Testing your actions in Shortcuts on Mac.
The report contains text describing completed moves. It is not a list of moved File objects. If you later extend the shortcut, do not treat those report lines as file input. Apple documents that actions accept and produce particular content types; use Show Info on an action to inspect its accepted input and resulting output. See Action connections in Shortcuts on Mac.
How does the naming rule preserve both copies?
For each source file, the script first checks the original destination path. If that path is occupied, it tries (2), then (3), continuing until a candidate is unused. Existing directories and symbolic links also count as occupied names. The final move uses mv -n as an additional no-overwrite check, following Apple’s mv(1) documentation.
| Incoming file | Destination already contains | Chosen destination name |
|---|---|---|
notes.txt |
Nothing with that name | notes.txt |
notes.txt |
notes.txt |
notes (2).txt |
notes.txt |
notes.txt, notes (2).txt |
notes (3).txt |
readme |
readme |
readme (2) |
archive.tar.gz |
archive.tar.gz |
archive.tar (2).gz |
These are the program’s naming rules, rather than a claim about Finder’s automatic naming. Only the final extension is separated: .gz stays at the end of archive.tar (2).gz. An incoming file already named notes (2).txt retains that stem, producing notes (2) (2).txt if necessary. The script does not interpret an existing number as a version.
The program quotes paths and iterates over shell-expanded filenames instead of splitting a text listing. Names containing spaces therefore remain single items. Its syntax deliberately uses Bash; keep /bin/bash selected. Apple’s Shell Script Basics explains why shell dialect differences matter.
Run the example and verify the result
Run the shortcut once, then inspect both folders in Finder. For the supplied synthetic data, the expected destination contents are:
notes.txt, still containingExisting synthetic notes.notes (2).txt, still containingEarlier synthetic second copy.notes (3).txt, containingIncoming synthetic notes.readme.txt, containingSynthetic readme.
The Incoming folder should now be empty, and the report should end with Completed: 2 file(s) moved. Running the shortcut again without adding files should report zero moves. These are expected results for the example; the full macOS Shortcuts workflow was not executed during preparation of this article. The filename-splitting expressions were checked separately with synthetic names.
If the shortcut stops, inspect both folders before rerunning it. Each file is moved individually, so an error on a later file does not reverse earlier moves. The script checks whether the source remains after each command rather than assuming every command completion means a file moved.
For an ordinary move failure, Apple recommends checking whether the file is open and whether the destination has enough available space. See If you can’t move or copy an item on Mac. A filename that becomes too long after adding a suffix can also prevent this program from completing that move; it stops rather than truncating the name.
The existence check and move are separate operations. This program is intended for a single, manually run local workflow, with stable folders. It does not reserve candidate names against simultaneous changes. Keep concurrent runs and other writers out of the example folders.
Use Finder when you only have a few collisions
For a small batch, explicitly rename the incoming file before moving it. In the synthetic example, inspect Collected, select Incoming/notes.txt, press Return, enter notes (3).txt, and press Return again. Apple documents this rename procedure in Rename files, folders and disks on Mac.
Then drag the renamed file into Collected on the same disk. Apple documents dragging an item into a folder to move it, holding Option to copy it, and holding Command when dragging to a different disk to move it. See Organize files in folders on Mac. If another name conflict appears, cancel that transfer and choose another unused name.
Once the disposable example behaves as expected on your Mac, adapt only src_dir and dst_dir for another pair of local folders with the same conditions. Keep the numbered-name loop and completion checks together: choosing an unused name preserves both destination copies, while checking the result tells you whether the incoming file actually moved.
Sources
- Meet Shortcuts for macOS — Apple Developer.
- mv(1) manual source — Apple Open Source Distributions.
- Organize files in folders on Mac — Apple Support.
- Show or hide filename extensions on Mac — Apple Support.
- Create a custom shortcut on Mac — Apple Support.
- Testing your actions in Shortcuts on Mac — Apple Support.
- Action connections in Shortcuts on Mac — Apple Support.
- Shell Script Basics — Apple Developer.
- If you can’t move or copy an item on Mac — Apple Support.
- Rename files, folders and disks on Mac — Apple Support.