0

I need to display on screen all the files that hang recursively from the root and that have not been modified in the last two days, with a size smaller than 5 KB.

I can show the files that hang recursively from the root with ls -R but it also show me directories, i dont know if is there any way to show only the files with the filters that i write.

I appreciate any help.

2

You should able to do that with find and something like:

find / -mtime +1 -type f
  1. find starting from root: /
  2. select anything that has not been modified in the last two days (48 hours): -mtime +1
  3. only select files: -type f

Be careful with units on mtime

As mentioned in comments and explained here, be aware of what the units on -mtime +1 means and then match that to your expectations.

  • Yeah! That is. I add -size 5k to limit the size to 5 Kb and done. Thank you! – TheRedosan May 13 '17 at 16:07
  • You fell into the trap. -mtime +2 is for the files whose age rounded down to an integer number of days is strictly greater than 2. So that's for files that are exactly 3 days old or older. – Stéphane Chazelas May 13 '17 at 16:33
  • @TheRedosan, -size 5k (in find implementations that support the k suffix) is for files whose size is inbetween 4097 (4KiB+1byte) and 5120 (5KiB). Use -size -5000c for files smaller than 5KB (between 0 and 4999 bytes). – Stéphane Chazelas May 13 '17 at 16:39
  • @StéphaneChazelas, thanks for the clarification. I added a note of explanation. – Stephen Rauch May 13 '17 at 16:43
  • IOW, -mtime +2 is for the files that have not been modified in the last 3 days. – Stéphane Chazelas May 13 '17 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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