copy files, get file names from a list

I am using a command:

xargs -a file_list.txt cp -t /path/to/dest 

but the filenames with whitespace get cut and therefore are not copied.

what can be done?


cat file_list.txt | tr '\n' '\0' | xargs -r0i cp -t /path/to/dest/ "{}"

You can do this

IFS=$'\n' ; for file in `cat file_list.txt` ; do cp $file /path/ ; done


  1. Set internal field separator to newline
  2. Read file_list.txt and loop through each line assigning contents of line to variable called $file
  3. On each loop, execute cp command on $file (you can add more steps too)

If it were a shell script and nicely formatted



for file in `cat file_list.txt` ; do {
  cp $file /path/
} done

Xargs is nice/fast/etc but isn't easy to understand for novices in shell scripting.

I think that's will be much more readable (and more clean than for with subshell).


while read filename; do
    cp -a "$filename" /path/to/dest
done < file_list.txt

Category: cp Time: 2016-07-30 Views: 0
Tags: xargs

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.164 (s). 12 q(s)