Find the answer to your Linux question:
Results 1 to 6 of 6
hi... 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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2006
    Posts
    2

    copy files only from dir & subdir


    hi...

    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?

    ie.
    /usr/options/textfiles/aug25/aug25.txt
    /usr/options/textfiles/aug26/aug26.txt
    /usr/options/textfiles/aug27/aug28.txt
    /usr/options/textfiles/aug28/aug27.txt
    /usr/options/textfiles/dates.txt

    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/

    thanks

  2. #2
    Linux Enthusiast
    Join Date
    Dec 2004
    Posts
    637
    maybe this:

    cp -r

  3. #3
    Just Joined!
    Join Date
    Sep 2006
    Posts
    2
    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. #4
    Just Joined!
    Join Date
    Nov 2006
    Posts
    1

    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'

    -punjester

  5. #5
    Just Joined!
    Join Date
    Nov 2013
    Posts
    1
    Simpler:

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

  6. #6
    Linux Engineer docbop's Avatar
    Join Date
    Nov 2009
    Location
    Woodshed, CA
    Posts
    940
    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
  •