Results 1 to 7 of 7

Thread: Copy command with piping

  1. #1
    Join Date
    Aug 2008
    Location
    Mexico and Sweden
    Posts
    1,669

    Default Copy command with piping

    Is there a copy command that allows piping from a text file? Something like...

    cat filelist.txt | copycommand --recursive destination_directory

    Thanks.

  2. #2

    Default Re: Copy command with piping

    Might want to explain what you actually want to do because I struggle to comprehend that. It sounds like you want to cat a file then copy recursively which makes no sense. Just copy recursively.

    I suspect what your trying to achieve is more than possible and probably wants redirection over a pipe, but as said can't give an exact as I'm really unsure what you're actually trying to achieve. It maybe that tee is better for the job.
    Man first, have a try at Info, have a look at Wiki, if all that fails Scroogle!!!!!
    If I've helped click on the Rep button I don't know what it does but it sounds cool.

  3. #3
    Join Date
    Aug 2008
    Location
    Mexico and Sweden
    Posts
    1,669

    Default Re: Copy command with piping

    I want to prepare a list of files and or directories in a file called filelist.txt to be copied to a specific existing directory to be named on the command line. "cat filelist.txt |" would pipe these as parameters to a copy utility. The filenames might exist in different directories or filesystems and will have no discernable patterns.

    Thanks for your help.

  4. #4

    Default Re: Copy command with piping

    rsync may be the easiest otherwise I suspect a rather convoluted function using a read could be done.

    rsync --files-from= which will take the file or - to use stdin. Check the man page for the exact syntax.
    Man first, have a try at Info, have a look at Wiki, if all that fails Scroogle!!!!!
    If I've helped click on the Rep button I don't know what it does but it sounds cool.

  5. #5
    Join Date
    Jun 2008
    Location
    /dev/belgium
    Posts
    1,946

    Default Re: Copy command with piping

    Code:
    for i in $(cat filelist.txt); do
        cp -f "$i" "/new/path/$i"
    done
    Something like this?

  6. #6
    Join Date
    Aug 2008
    Location
    Mexico and Sweden
    Posts
    1,669

    Default Re: Copy command with piping

    Thank you very much people. The second solution looks quite elegant, but I will try both.

  7. #7

    Default Re: Copy command with piping

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    - From the man page:

    SYNOPSIS
    cp [OPTION]... [-T] SOURCE DEST
    cp [OPTION]... SOURCE... DIRECTORY
    cp [OPTION]... -t DIRECTORY SOURCE...

    So....

    cp -t /path/to/destination `cat filelist.txt | xargs`

    I have not tested this yet, but it looks good to me.

    Good luck.





    ionmich wrote:
    > Thank you very much people. The second solution looks quite elegant, but
    > I will try both.
    >
    >

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v2.0.9 (GNU/Linux)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

    iQIcBAEBAgAGBQJKchkpAAoJEF+XTK08PnB5lbAQAMYxQNzPr9KAQ9NN6bsc60z4
    m9A0H0Fe5kKt+plmc6bqjLdF/jz3DElXnWmP/7yG3IGKI8uar5FSIZWURRuE4UwZ
    uAZnUGdeB4eJ1ly0j9aZhYnysNrmLgVIN9igTe03evJghQe29JWTrM5h4I3AqR5m
    3Y3KzFDf6eZlx4hgCE9lNIy/Iuk5OPqzuVnTXm56Qix+G83Tlp9KXM2lKmilPU6U
    O3/f+Fr6dNuj/tPCVRZ18FNVvzpzRx3RZHpkm6Ll3z2Z1tZL/P/BnQGpUaQq4jeX
    Sm7AGVKeTzzbrYHzDT4bVeZjXk2QWRMVB/t4WczGJfGVPFq29p5OxIOyTe/OC9qv
    a+a99HWj0v+1l49KzsqOXiv8bKHhGvExwTcsGfNApi8xopxXoO+Jhvbg9q4Qs8GL
    0PGMevVL+QIW1smxR2a9Li4q+RfH6NowAn1olY/mnTO4iH/JY7cRKKZ0Y0qPvXLx
    a3mmvxsx0gZ2NFS0bwJ2uy3XhFxlFunP0eVWlY4OO8Y16IHVu65atknWsZfT2WmW
    9sZdqOJNeSBsQk4I/MQtfUMOGSZo9/Y+xZ7FeBAEvY2pyRXJf8/3muGVCoRMzYbc
    R/Dyeq3TpKbtcxe2je1LCD8vFICD2ypotWO9GP/icRYqaKPSNFQ+RaTCmSzoli/r
    /plGAKsAyQfvz8nfAZG+
    =VTM1
    -----END PGP SIGNATURE-----

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •