Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to find a set of files to remove that have not been access since their last inode change. Files in which the last activity happened when they were moved into the directory they are currently in.

Here I try to pass each file in as the reference file for the find test -newer

man find 
...
-newerXY reference
          Compares  the timestamp of the current file with reference.   
...    

This is what I have tried so far but it does not work.

find . -type f | xargs -I{} find -newerac {} -printf "%p\tinode: %i\naccess: \t%a\nchange: \t%c\n"
share|improve this question
    
For some more info about how atime is handled by newer kernels. superuser.com/a/464737/67952 –  nelaar Aug 22 '12 at 8:40

1 Answer 1

up vote 2 down vote accepted

This gives you all files that differ between atime and ctime:

find . -type f -printf "%p\n%a\n%c\n\n" | \
  awk 'BEGIN {FS="\n"; RS=""}; $2!=$3 {print $1}'

See this example:

ls -1
data
data1
ss.08-02-2012-01.22.16-PM.png
ss.09-02-2012-13.42.06-PM.png
test.awk
test.py
test.sh

Now look at the file stats:

find . -type f -printf "%p\n%a\n%c\n\n"
./test.sh
Tue Aug 21 15:12:29.0000000000 2012
Tue Aug 21 15:12:29.0000000000 2012

./data1
Tue Aug 21 15:13:13.0000000000 2012
Tue Aug 21 15:12:29.0000000000 2012

./test.awk
Tue Aug 21 15:12:29.0000000000 2012
Tue Aug 21 15:12:29.0000000000 2012

./data
Tue Aug 21 15:12:29.0000000000 2012
Tue Aug 21 15:12:29.0000000000 2012

./test.py
Tue Aug 21 15:12:29.0000000000 2012
Tue Aug 21 15:12:29.0000000000 2012

./ss.09-02-2012-13.42.06-PM.png
Tue Aug 21 15:12:29.0000000000 2012
Tue Aug 21 15:12:29.0000000000 2012

./ss.08-02-2012-01.22.16-PM.png
Tue Aug 21 15:12:29.0000000000 2012
Tue Aug 21 15:12:29.0000000000 2012

I separate each field by newline and each record by blank line to ease following processing with awk: awk 'BEGIN {FS="\n"; RS=""}; $2!=$3 {print $1}'
Here the field separator and the record separator are set at the beginning (RS interprets empty string as blank line). That means $2 and $3 hold the atime and ctime. If they differ the according filename (in $1) is printed.

The result here is:

./data1
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.