I looked for relevant posts extensively before writing but I apologise if it has been already asked and solved.
I'd need to find, select and move/copy some files from a folder starting from a list in a text file (but could also paste it directly if needed).
I've found some posts that could've helped and more precisely the ones at the following link: https://stackoverflow.com/questions/29311880/finding-files-from-list-and-copying-them-into-new-directory
This seems perfect but I've got a permission error (cp: /found_files: Permission denied
) and couldn't find a work around (tried sudo
and many other combinations).
This one seemed fine as well: Find multiple files at once via Terminal. It works very well to find the files but I couldn't find a way to select them in order to be able to move/copy them to a new directory.
Tried all this on macOS Sierra 10.12.6 with no special configurations or changes in the Terminal.
Best Answer
You get
cp: /found_files: Permission denied
because the script in the linked post, in its current form, is written to copy the listed files to the/found_files
directory. The/found_files
directory doesn't exist on your Mac andcp
interpretsfound_files
as a file located in/
. Since/
is not writable, you get the permission error.I modified the script so that it works with other destination directories and expanded it to support copying and moving files:
Launch Terminal. Select a directory where you save your scripts, for example
~/bin
:Create a file named
cplist.sh
with these contents:Make the file executable:
Link the file to
mvlist.sh
:To copy a set of files, use
cplist.sh
as follows:where
<file list>
is a text file that contains file names, for example:To move a set of files, use
mvlist.sh
as follows:For example: