ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm trying to copy all the files in one partition to a folder in another partition. I want all the files that have a certain phrase in the file name to be copied. for instance: I want all files with 'school' in the file name to be copied to the folder /home/backups/school. what command would work best for this?
you don't need grep, find can do pattern matching with -name or -iname arg. something like: 'find /path -iname '*school*' -exec cp /home/backups/school "{}" ";"'
I suggest you to use the command xargs.
Then you would have something like this:
--> find | grep school | xargs -n1 -i cp -r {} /home/backups/school
The curly braces mean for every argument you get to the pipe.
BTW infamous41md: -name does not search for a string inside a file, but searches a file that conatins in its name that string (-iname is the same but for case insensitive).
Last edited by Charalambos; 08-15-2004 at 07:14 PM.
he said "a certain phrase in the filename", and the example i gave did just that. quantus, the command i gave works fine. maybe u copied it wrong. i suggest reading the man page find, type 'man find' [enter].
ok, i copied the text exactly. and entered it into the shell prompt. all it did was bring me to the " > " prompt.
guys, my question was that is there any way to pipe the stdout into a command.
for instance, if {} were the way to pipe all stdout into a certain spot, then this command would retrieve all log files and copy them to a certain directory.
find / | grep .log|cp {} /logbackups/today
see? i'm trying to learn how to master the stdout manipulation. and i haven't found anything related to the above situation in any tutorial. thanks.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.