Let's say I have 7000+ directories somewhere, each of which contains subdirectories and some files. I am only interested in a small proportion (maybe 700+) of the 7k+ directories, and I have the names of these directories. I want to copy only the 700+ directories together with their contents to a new location. How can I do that? Thanks a lot in advance!
1 Answer
The answer to this depends entirely upon how you have formatted your your list of directories, mostly depending upon the delimiter. Assuming it is a file seperated by newlines:
cat directories.txt | while read line; do mv $line /path/to/destination; done
`
-
(1) Unless
directories.txt
is deliberately designed to be used with plainread
, one should strongly preferIFS= read -r line
. (2) In many shells unquoted$line
is a bug. Sep 29, 2020 at 18:28