'-exec cmd' in find command (10 Views)
Reply
Super Advisor
Gary Yu
Posts: 253
Registered: ‎08-07-2001
Message 1 of 4 (10 Views)
Accepted Solution

'-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 ??? {} \;
Trusted Contributor
Jan Sladky
Posts: 241
Registered: ‎05-12-2004
Message 2 of 4 (10 Views)

Re: '-exec cmd' in find command

Hi,

try

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

br Jan
GSM, Intelligent Networks, UNIX
Honored Contributor
Muthukumar_5
Posts: 4,030
Registered: ‎06-09-2004
Message 3 of 4 (10 Views)

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
Gary Yu
Posts: 253
Registered: ‎08-07-2001
Message 4 of 4 (10 Views)

Re: '-exec cmd' in find command

thank you guys, it works fine!
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.