in reply to Re: Copying a list of files from a directory to a new directory
in thread Copying a list of files from a directory to a new directory

The -f - is redundant, AFAIK. Then, newer (at least GNU) tar has a -T option (or --files-from) which eliminates the need for xargs, and a -C option (or --directory) which eliminates the need for cd and the parentheses

This simplifies the script to
tar c -C source -T mylist.txt | tar xC dest
(Tested with MinGW on Win7)

Of course, your script could be written right out of your head, while I had to open the man page for looking up the letter of that filelist option...

Replies are listed 'Best First'.
Re^3: Copying a list of files from a directory to a new directory
by roboticus (Chancellor) on Jul 21, 2018 at 20:27 UTC

    soonix:

    Heh, heh! In fact, when I was writing that response, I thought that tar would have such an option. But after listing through the first three or so pages of the dox, I got tired of looking. Then I thought I'd just xargs to convert the file into a list of command-line arguments. I nearly wrote it as cat mylist.txt | xargs | ... but didn't want to earn another "useless use of cat" award, so I just used xargs <mylist.txt to do the task.

    After your response, I again looked at man tar and found the option ... on the thirteenth page! Since my terminal is 57 lines long, that seems a bit excessive. I'm thinking that the man page for tar ought to be rearranged a bit, as that sounds like an option that's generally useful, and there are quite a few options that seem to be much more specialized, and hence useful in fewer situations. (I've never needed --hole-detection or --check-device both of which are on page 4.) Now that I'm aware of -T, though, I'll hopefully remember it for the next time. ;^)

    ...roboticus

    When your only tool is tar, all problems look like you're gonna have to read "War and Peace", possibly several times.