I'm trying to understand the output of the find command with the -cnewer
test. In doing some limited testing, this is what I get.
First, I created a file:
cd ~/Documents
touch file1.txt
Then I waited a few minutes before creating another file:
touch file2.txt
Then I decided to compare the content timestamp to the metadata timestamp by doing:
ls -lht (for content timestamp)
-rw-rw-r-- 1 mason mason 0 Aug 11 01:19 file2.txt
-rw-rw-r-- 1 mason mason 0 Aug 11 01:17 file1.txt
And then:
ls -lhtc (for metadata timestamp)
-rw-rw-r-- 1 mason mason 0 Aug 11 01:19 file2.txt
-rw-rw-r-- 1 mason mason 0 Aug 11 01:17 file1.txt
So far no surprises, since I haven't done anything to change the metadata timestamp.
Now if I type:
chmod 664 file1.txt
to change the metadata timestamp, and then look at the output again:
ls -lhtc
-rw-rw-r-- 1 mason mason 0 Aug 11 01:23 file1.txt
-rw-rw-r-- 1 mason mason 0 Aug 11 01:19 file2.txt
file1.txt
appears in first position in the ls -lhtc
output, but still in second position in the ls -lht
output, also as expected.
Finally, if I decide to type:
cd ~/Documents
find . -cnewer file1.txt
I get:
.
./file2.txt
./file1.txt
Here are the questions I have:
What does
-cnewer
look for? Does it look to see if the metadata timestamp has changed or does it look for whether the content timestamp has changed? Does it do both? I'm pretty sure it does both, but I'd like to be sure.If
-cnewer
does both, why doesfile1.txt
end up in the output? I can understand whyfile2.txt
ends up in the output, since find will look for a more recent content timestamp thanfile1.txt
, but I still don't understand whyfile1.txt
ends up in the output. After all, there is no file with a more recent metadata timestamp in thels -lhtc
output thanfile1.txt
.