#!/bin/bashunset resultresult=$(find /home -path $HOME/TestDir/[0-9][0-9][0-9][0-9]/test* -mtime -7 -print -delete 2>/dev/null)[ $result ] || echo There are no recovery files older than 7 daysIn the /test part I actually need to find 2 file names. Those that begin with E* and those that begin with P_*. can this be done?
BASH script to search for files in folders of 4 digits and older than 7 days
bash;shell script
find $(find -name [0-9][0-9][0-9][0-9]) -name [test]* -mtime -7 -exec rm -i {} \; || echo There are no recovery files older than 7 daysThe || (or) operator looks at the result of the command on its left, and runs the command on the right only if the command on the left failed (based on the return code).If find does not find any matching files, it will return 1, which will cause || to run run the echo command.