Quantcast
Channel: conditional find output missing - Ask Ubuntu
Viewing all articles
Browse latest Browse all 3

Answer by Ravexina for conditional find output missing

$
0
0

One liner workaround:

find -size +10G | grep ".*" > file.log || (rm file.log; echo "Can't find anything")

Or:

find -size +10G | grep ".*" > file.log || rm file.log

Note that find returns 1 (False) when files are not processed correctly for any reason, so I suggest using something like:

#!/bin/bash
RESULTS=$(find /path -size +1G)
if [ -n "$RESULTS" ];
 then
   echo "$RESULTS" > /path/file.log
fi

First run the find and put the results in a variable, then if the variable contained anything save that into a log file.


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>