Expert cp command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expert cp command
# 1  
Old 03-26-2010
Expert cp command

How can I use the cp command to copy every file that I can find inside several folders

Code:
cp -R *test* folder

Supose there is
./122342343teste122343.txt
./bound/123teste1223453.txt
./feed/123teste1223453.txt

and i want the files 122342343teste122343.txt, bound/123teste1223453.txt and feed/123teste1223453.txt to folder using one line of command.

Thanks !
Felipe
# 2  
Old 03-26-2010
Which OS?

./bound/123teste1223453.txt will overwrite ./feed/123teste1223453.txt in the target dir ...

Or you want to recreate the directory structure too?
# 3  
Old 03-26-2010
on unix, there are diferent files, but they have some key in the name that are equal.

I want to copy all files to one directory.

Tks
# 4  
Old 03-26-2010
On Unix ...

On some systems (GNU Linux, I'm not sure about BSD),
you could run the following command:

Code:
find -type f -name '*test*' -print0 |
  xargs -0 cp -t <dest_dir> --

Otherwise, it will be slow:

Code:
find . -type f -name '*test*' | 
  while IFS= read -r; do
    cp -- "$REPLY" <dest_dir>
  done

Or, of course, if the directory depth is known:

Code:
cp -- */*test* *test* <dest_dir>

# 5  
Old 03-26-2010
I tried the second one and the script did not look inside the folders, did not copy the files from others folders...


> find -type f -name '*test*' -print0 |
> xargs -0 cp -t filezip
xargs: illegal option -- 0
xargs: Usage: xargs: [-t] [-p] [-e[eofstr]] [-E eofstr] [-I replstr] [-i[replstr]] [-L #] [-l[#]] [-n # [-x]] [-s size] [cmd [args ...]]
find: illegal option -- t
find: [-H | -L] path-list predicate-list

and the seconds commands also did not copy the files ./bound/234test235.txt, ./feed/687est687.txt
# 6  
Old 03-27-2010
MySQL

you can try this:

Code:
 
find -name "*teste*" -type f | xargs cp -t folder/

And I cant see any error in radoulov's solutions.

Are you working on FreeBSD or MacOS?

Last edited by ygemici; 03-27-2010 at 11:26 AM..
# 7  
Old 03-29-2010
Deu erro.

Code:
find -name "*est*" -type f | xargs cp -t filezip/
find: illegal option -- n
find: [-H | -L] path-list predicate-list
cp: illegal option -- t
cp: Insufficient arguments (1)
Usage: cp [-f] [-i] [-p] [-@] f1 f2
       cp [-f] [-i] [-p] [-@] f1 ... fn d1
       cp -r|-R [-H|-L|-P] [-f] [-i] [-p] [-@] d1 ... dn-1 dn

I am on UNIX....
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to expert Shell Programming ?

Guys, I have been reading the bash books, there are so many command & operators etc. The theory part is so much. Overall I have read some book. Still do not feel I know the bash with confidence. Lots of Jobs for System Admin demand Scripting knowledge as requirement .. I think I should... (7 Replies)
Discussion started by: heman96
7 Replies

2. Solaris

Becoming a Solaris expert?

Hello everyone, how do you really study to become an expert in solaris OS? Thanks (3 Replies)
Discussion started by: cjashu
3 Replies

3. Solaris

Could not able to delete the files through find command need expert advice

Hi Gurus I am facing a problem, there is a folder called /a where there are lots of files which are occupying space anything between 30 GB to 100 GB as I am not able to check the space occupied by that folder through "du -sh /a" command as I don't see any output after more than 1 hour of... (4 Replies)
Discussion started by: amity
4 Replies

4. UNIX for Advanced & Expert Users

Expert Opinion

This perhaps does not belong in ths category; apologies, however, we have a heated debate going and your input will decide the result. Should UNIX (HP, AIX, etc) be rebooted following a monthly cycle (Every month, or a qtr, etc.). We have some UX admins (grumps) who say they have seen a UX... (6 Replies)
Discussion started by: rsheikh
6 Replies

5. Programming

Perl and Expert Systems

Hi, I'm designing / writing a system which would analyze results of a load test and determine whether test passed or failed. The trouble is, the pass/fail criteria is very complex. And it may vary. So I'm thinking of something similar to Expert Systems. One idea is put the rules in XML... (3 Replies)
Discussion started by: Yogesh Sawant
3 Replies

6. Solaris

expert vi commands

:) Hi UNIX friends, Where do I get advanced vi commands to practice. Please Help Me. Love (4 Replies)
Discussion started by: Love
4 Replies

7. Linux

I am a beginner.Wanna become expert.

Hi Everybody, I am beginner to Unix platform, Can anybody guide me to learn the Unix, Scripting, shell scripting and inside stuff. I am interesting in programming that needs the step by step walk. Thankful to those who dare to walk along. yours farooq (5 Replies)
Discussion started by: farooq_kdp
5 Replies
Login or Register to Ask a Question