InterviewSolution
Saved Bookmarks
| 1. |
Solve : copying recursively and pruning? |
|
Answer» hello all, IVE got a simple question, but i havent found the simple answer, or any answer for that matter. I'd like to copy a hierarchy of files, but with a catch: i only WANT the .txt files. cp has the recursive option -r which copies everything Code: [Select]cp -r foo/* bar but i just want the .txt files. i thought it might work to do this: Code: [Select]cp -r foo/*.txt barbut this doesnt recurse (obviously since my folders dont END with .txt) What can i do? Thanks in advance! Have a look at FIND (man find). The -exec option should help. Also have a look at xargs. This is taken from my man pages: Code: [Select]EXAMPLES find /tmp -name core -type f -print | xargs /bin/rm -f Find files named core in or below the directory /tmp and delete them. Note that this will work incorrectly if there are any filenames containing newlines or spaces. find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f Find files named core in or below the directory /tmp and delete them, processing filenames in such a way that file or directory NAMES containing spaces or newlines are correctly handled. Code: [Select]cp -R *.txt destination |
|