简体   繁体   中英

Move files from one directory to another based on file names in csv using macOS Terminal

I am trying to move thousands of files from one directory to another based on the file names that are in a CSV document (one column with just the names).

CSV:

filename1
filename2
filename3

Folder

filenameA
filename1
filename2
filename3
filenameZ

NewFolder (after the operation is complete)

filename1
filename2
filename3

I am trying to do it this way:

cat /Users/xxxxx/files.csv | xargs -I {} find /Users/xxxxx/Documents/Folder/ -type f -name "{}*" -exec cp {} /Users/xxxxx/Documents/NewFolder/ \;

But it only searches for the last name listed in the csv and ignores all the other names.

In your terminal window, you can use this command to move files listed in CSV from Folder to NewFolder:

for file in $(cat CSV); do mv Folder/$file NewFolder; done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM