Tony
Tony

Reputation: 35

How to loop through a directory that includes files and hidden files

I am trying to compare a given file and compare it to a directory's files to see if any of the files within the directory are newer than the file given. I want to go through all files in the given directory including hidden files. I cannot figure out how.

I've tried changing "direct"/; to "direct"/. but it will only include the hidden files then but not all of the other files that are within the given directory.

inputfile=$1 
direct=$2  
for file in "$direct"/*; do
if [[ $file -nt $inputfile ]] 
then
echo $(stat $file | grep Modify | cut -d' ' -f2,3) #formatting
fi
done

Upvotes: 1

Views: 395

Answers (1)

Daniel Da Cunha
Daniel Da Cunha

Reputation: 1004

You can use the find command to achieved this as per this other answer: Delete files older than specific file

inputfile=$1 
direct=$2 
find $direct/ -type f ! -newer $inputfile

Upvotes: 1

Related Questions