samedi 20 janvier 2018

How to use bash's find arguments in if statements?

Just as the title says. I know how to use find's arguments in line with it, but not how to use them as if statements while evaluating a find return variable. For example:

find . -type f

This obviously finds all the files, and how I'm looking to use it is:

ARRAY=$(find .)
for item in $ARRAY
do
if [[ -f $item ]] ; then

And that does the same thing, it only deals with the files from the find. I obviously know how to do it with the -type argument, but not the others. For example:

find . -size +512k

if I want size, doing if [[ -size +512k $item ]] doesn't seem to work as expected. How do I use it?

Others I can't figure out how to use:

find . -executable
find . \( -name "*.html" -or -name "*.css" \)
find . -mtime +364

How would I use each of these in if statements if I'm looping over the results of a find?

Additionally, how would I grab the total size of a find result, after the fact, not during the find. Say I have my ARRAY=$(find .) and what to do a du -ch against my $ARRAY variable. How would I do that?

Sorry, I'm a bash noob and its syntax is proving difficult for me.

Aucun commentaire:

Enregistrer un commentaire