Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

copying a list of files via terminal

I have a list of filenames called list.txt.

I would like to copy the files in this list to a new folder.

How should I go about doing this?

Thanks!

like image 504
dot Avatar asked Nov 10 '09 23:11

dot


People also ask

How do I get a list of files in terminal?

To list files in a terminal, you use the ls command to list all files in the current directory. The pwd commands tells you what directory you're currently in.

How do you copy multiple files in Linux terminal?

To copy multiple files you can use wildcards (cp *. extension) having same pattern. Syntax: cp *.

How do I copy a list of files in a text?

Right-click that folder and select Show more options. Click Copy File List to Clipboard on the classic menu. You'll still need to paste the copied list into a text file. Launch Run, type Notepad in the Open box, and click OK.


1 Answers

You can do this:

cp `cat list.txt` new-folder/

Note that you should avoid having spaces in your filenames when using this (another solution would be needed if this is the case).

The backticks execute the cat list.txt command and use the output of that command as part of the command line to cp. Newlines in the output of cat are collapsed to spaces before command line substitution.

like image 120
Greg Hewgill Avatar answered Oct 09 '22 01:10

Greg Hewgill