0

When taking screenshots on MacOS, the second monitor content is in file xxxx(2).png

If a user (poweruser on Windows but newbie on MacOS) wants a script that moves all screenshot with *(2).* to folder "two", how is it done via script/command line?

The command below does not work. It moves all files and the user needs just half of the files moved.

mkdir two
mv *(2).* two

What is the correct mv command?

Files containing (2) fragment in file name (at the end of the name) need to be moved.

Example of file name from second monitor is 'ssht 2022-04-27 at 12.19.55 PM (2).png'. That need to be moved.

Example of file from first monitor is ssht 2022-04-27 at 12.19.55 PM.png

(and ideally making it clickable/executable (chmod or .command or bash mymovecmd.sh)

man mv does not talk at all about any star notation for moving files. Not sure if mv on macos suports globbing and how to use it. https://stackoverflow.com/questions/28176590/what-do-double-asterisk-wildcards-mean

1
  • mkdir two;find . -name '*(2)*' -exec mv '{}' two \; but I have little idea why is this correct Commented Apr 29, 2022 at 21:11

1 Answer 1

1

Wildcards/patterns are handled by your shell usually (mv for instance doesn't know anything about patterns in filenames, that's why you can have file names with * in them), so in the case of

mv *(2).* two

your shell tries to expand *(2).* before mv is even called. Because *(2) has a special meaning in both bash and zsh (a different one though) this will not expand into something you would expect (run echo *(2).* to see what it actually does).

You can prevent this by escaping the paranthesis

mv *\(2\).* two

PS: The reason the find command works is because in this case the regexp is handled by find itself (as you put it in '' and find needs to handle regexps itself to expand them for each item it scans).

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.