move file by list in file (with leading whitespace)
You are just missing the -t
option for mv
(assuming GNU mv
):
cat /tmp/list.txt | xargs mv -t /app/dest/
or shorter (inspired by X Tian's answer):
xargs mv -t /app/dest/ < /tmp/list.txt
the leading (and possible trailing) spaces are removed. Spaces within the filenames will lead to problems.
If you have spaces or tabs or quotes or backslashes in the filenames, assuming GNU xargs
you can use:
sed 's/^ *//' < /tmp/list.txt | xargs -d '\n' mv -t /app/dest/
Assuming your file names are relatively sane (no newlines or weird characters):
while read file; do mv "$file" /app/dest/; done < list.txt
To deal with weird file names (breaks if a file name has a newline):
while IFS= read -r file; do mv "$file" /app/dest/; done < list.txt
for i in $(cat /tmp/list.txt); do mv "$i" /app/dest/; done