Steve
Steve

Reputation: 4691

Redirect output from -exec in find command to variable

I have a command in the form:

find -name *.* -type f -exec rm {} -v \;

And I want to get the list of files that it processed into a variable. How would I do that in ksh?

Upvotes: 1

Views: 2665

Answers (4)

user unknown
user unknown

Reputation: 36229

I'm not a ksh-user, so I might be wrong. In bash, I have to mask the asteriks:

find -name "*.*" -type f -exec rm {} -v \;

and I can use -delete instead of -exec rm, but delete is special for GNU-find:

find -name "*.*" -type f -delete

and to output the file names, append a print:

find -name "*.*" -type f -delete -print

and capture the output

deleted=$(find -name "*.*" -type f -delete -print)

Upvotes: 0

Paul Nikonowicz
Paul Nikonowicz

Reputation: 3903

Here's an example:

VAR=$(your statement)

Upvotes: 0

quicoju
quicoju

Reputation: 1711

 VAR=`find /dir -name '*.*' -type f -print -exec rm {} \;`

Upvotes: 1

Dennis C
Dennis C

Reputation: 24747

Append a "-print" after your arguments

Upvotes: 0

Related Questions