user1344959
user1344959

Reputation: 41

Copying files using Terminal, Mac

I am trying to copy files from one folder to another using terminal. I have a folder with thousands of files in it and I have a txt list with thousands of file names that match them. I need to copy only the files that are on the txt list to a new location.

I found this online and modified it for my disks but it is not working. Today is the first time I have ever opened Terminal so I don't know what I am doing of if this is even close to what I need. Any advice would be appreciated.

#!/bin/bash

target="/Users/DataSourceSTL/Desktop/Photos"
destination="/Users/DataSourceSTL/Desktop/Test"

fnames=”/Users/DataSourceSTL/Desktop/Untitled.txt”

for info in $fnames; do
  cp ${target}/${info} ${destination}/
  exit 1
  echo "copying $info"
done

echo "done"

Upvotes: 4

Views: 7024

Answers (1)

Skippy Fastol
Skippy Fastol

Reputation: 1775

Try this :

for info in `cat $fnames`; do 
  cp -v "${target}/${info}" "${destination}/"
done 
echo "done"

Upvotes: 2

Related Questions