Find the answer to your Linux question:
Results 1 to 6 of 6
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    copy files only from dir & subdir


    i need a heads up on how to use cp to do coplex copying...
    i have a directory which in turn contains subdirectors with *.txt files in each.

    what is the cp command to copy all *.txt files from all subdirectories within that directory?


    i need to copy all *.txt files in /usr/options/textfiles/ into one directory, ie. hav all the *.txt files all in my other directory /usr/text/


  2. #2
    maybe this:

    cp -r

  3. #3
    cp -r copies the directory and files.. is there a way just to extract the files?

    i'm sorta want to do this..
    find /usr/options/textfiles | grep .txt
    copy (the result of find) to /usr/text/

    is there a cp option that does this?

  4. $spacer_open
  5. #4

    copy files from subdirectory with find and xargs

    This should do the trick for you:

    find /usr/options/textfiles/ -name *.txt -type f -print0 |xargs -0 -i cp {} /usr/text/

    those are zeros up there for '-print0' and 'xargs -0'


  6. #5

    cp `find /source -name *.txt` /destination

  7. #6
    Linux Engineer docbop's Avatar
    Join Date
    Nov 2009
    Woodshed, CA
    This works for me

    find ./basePath/ -name *.txt -exec cp {} targetPath \;

Posting Permissions

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