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.

muru
  • 69,900
  • 13
  • 192
  • 292
TheRedosan
  • 11
  • 2
  • What do you mean by "files that hang recursively from the root"? – Satō Katsura May 13 '17 at 15:53
  • @Sato, files hang from the directory tree, like apples hang from the apple tree. – Stéphane Chazelas May 13 '17 at 15:55
  • All the files that are inside all the folders that hang from the root, and if that folder has another folder inside with more files, that also shows those files. That's what ls -R does. – TheRedosan May 13 '17 at 15:59
  • There are many related Qs and even duplicates e.g. [Files greater than 1 GB and older than 6 months](https://unix.stackexchange.com/q/203129) or [Find files that match a certain size and modification time?](https://unix.stackexchange.com/q/258737) – don_crissti May 13 '17 at 16:01
  • Ok, nice! Im going to try with this and the answer of Stephen. – TheRedosan May 13 '17 at 16:05

1 Answers1

1

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.

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
Stephen Rauch
  • 4,209
  • 14
  • 22
  • 32
  • 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