Command Line – How to Copy/Move a List of Files to a New Directory

bashcommand line

I have an huge amount of files (e.g. 110011basz.dat, 110012basz.dat, 110013basz.dat,…) inside a folder, call folder. On the other hand I have a list related to the files I need to move to another folder (let´s call it folder2). This list doesn't show the full name of the files but just the prefix such as 110011.

Now how can I move those files into folder2?

Thank you for your help!

Best Answer

Assuming list.txt has names of files (with only prefix) one in each line, the following code will move all listed files to folder2:

while read file; do mv "$file"basz.dat /path/to/folder2; done < /path/to/list.txt
Related Question