1752381 Members
5647 Online
108788 Solutions
New Discussion юеВ

find command

 
SOLVED
Go to solution
Ravi_65
Occasional Contributor

find command

Is it possible to find some files and copy them to a different folder in a single command line (find) ?
No limit to learning.
6 REPLIES 6
Petr Simik_1
Valued Contributor
Solution

Re: find command

-exec does this , you can execute more commands by chaining -exec after find command. Important - dont forget \; at the end.

find / -name "file" -exec cp -p {} /dir/ \;

find / -name file -exec cp {} /dir \; -exec ll {} \;





Ravi_65
Occasional Contributor

Re: find command

Thanx Petr

-Ravi
No limit to learning.
Indira Aramandla
Honored Contributor

Re: find command

Hi,

You can do by using find and cpio in one command.

to find a list of files after a certain period, you can make use of the -newer parameter. other wise you could use mtime and atime.

Eg:

find /path_name -name "*file_string*" -mtime +1 -print | cpio -p /new_loacation_path.


IA.
Never give up, Keep Trying
Jose Mosquera
Honored Contributor

Re: find command

Hi,

#find / -type f -name "*string*" -exec cp -p {} \;

"-type f" optimizes the search, indicating that just looks for files (it omits directories, links, etc).

If you are ussing wilcards to find a file group you will contain it among " "

Rgds
Stefan Schulz
Honored Contributor

Re: find command

Hi,

this can be done with teh -exec option of find. Something like

find . -type f -exec cp -p {} /yourdir \;

where {} ist the result of the find given to the copy command. And \; ends the copy command.

But in this case for every single file this will start a seperate cp process, copy the file and end the cp process.

This can be pretty slow if you have e.g. several thousand files to copy. If you have only a limited number of files to copy this is an easy way.

Hope this helps

Regards Stefan
No Mouse found. System halted. Press Mousebutton to continue.
Stefan Schulz
Honored Contributor

Re: find command

Uuups seems that it took me far to long to key in my reply.

I would be much faster with my replies if there where no users (asking oh so important questions) around.

Regards Stefan
No Mouse found. System halted. Press Mousebutton to continue.