System Administration
Showing results for 
Search instead for 
Do you mean 

'-exec cmd' in find command

SOLVED
Go to Solution
Super Advisor Super Advisor

'-exec cmd' in find command

Dear all,

Does anyone know how to specify 2 parameters with the '-exec cmd' in find. e.g, I need to copy all files for the last week to another directoy, but it looks to me the cmd with -exec only takes one parameters(like rm), so how can I do that with one line, instead of a script:
find . -type f -mtime -7 -exec ??? {} \;
1 ACCEPTED SOLUTION
Trusted Contributor Trusted Contributor

Re: '-exec cmd' in find command

Hi,

try

find . -type f -mtime -7 -exec cp {} /dir \;

br Jan
GSM, Intelligent Networks, UNIX
3 REPLIES
Trusted Contributor Trusted Contributor

Re: '-exec cmd' in find command

Hi,

try

find . -type f -mtime -7 -exec cp {} /dir \;

br Jan
GSM, Intelligent Networks, UNIX
Honored Contributor Honored Contributor

Re: '-exec cmd' in find command


Collected files on using find commands are given as {} to -exec option.

find . -type f -mtine -7 -exec cp {} /destination-dir/ \;

You can use multiple -exec there as,

find . -type f -mtine -7 -exec ll {} \; -exec cp {} /destination-dir/ \;
Easy to suggest when don't know about the problem!
Super Advisor Super Advisor

Re: '-exec cmd' in find command

thank you guys, it works fine!