I would like to take the results from this command:
find . -type f -size +200M -exec ls -lh {} \;
store the content to a variable of some form, and then delete the found files.
How can I do this?
I would like to take the results from this command:
find . -type f -size +200M -exec ls -lh {} \;
store the content to a variable of some form, and then delete the found files.
How can I do this?
You don't need to store the results of find in variable only to be able to remove the files (unless you've some specific requirements which you didn't mention), as find provides special -delete parameter which would do that for you:
find . -type f -size +200M -print -delete
As parsing output of ls command is not advised.
If you really want to parse the files returned by find, you need to do something like:
find . -type f -size +200M -print0 | xargs -0 rm -v
Since you can't keep shell variables with null characters, and you don't want to break the script on spaces (which can cause giant bugs), the workaround could be to store the list in the temporary file or serialize the data (e.g. base64).