I generally know what find ~ –mtime -30 -print does. It finds all the files that have been modified within the last 30 days. However, I can't figure out what -print is doing. Yes, I tried looking at the documentation, and it says it prints the full name followed by a new line. However, removing -print seems to achieve the same results. So what's the difference?
Asked
Active
Viewed 29 times
0
Grateful
- 113
- 2
-
With no args, the default is exactly -print. If you want to print *and do something else too*, you will need to explicitly -print because there is another command. – Paul_Pedant Jan 29 '23 at 09:46
-
Okay... So, without any arguments, the default is the same as `-print`. But in this case, because I have `-mtime` I need the `-print`? But then I don't understand why in this particular case, the results are the same. Do I need `-print` here or not? – Grateful Jan 29 '23 at 09:50
-
1From the man page (emphasis added): _"The `-print` action is performed on all files for which the whole expression is true, **unless** it contains an action other than `-prune` or `-quit`. Actions which inhibit the default `-print` are `-delete`, `-exec`, `-execdir`, `-ok`, `-okdir`, `-fls`, `-fprint`, `-fprintf`, `-ls`, `-print` and `-printf`."_ – rickhg12hs Jan 29 '23 at 09:58
-
@Paul_Pedant : *expression* not *args* ;-) : *"If no expression is given, the expression -print is used"* – MC68020 Jan 29 '23 at 10:00
-
I am afraid, I am not able to fully comprehend that text... Which is why I am still having problems. So, can you please confirm, `-print` is used by default for everything unless you have another option... So, does that mean adding `-mtime` then requires us to add `-print` additionally... Since, it is another action? However, if that is the case, I still don't understand why the command in the question gives the same result regardless of whether `-print` is added or not? Very very confusing!!! – Grateful Jan 29 '23 at 10:03
-
From the man page, `-mtime` is not in the set of actions "`-delete`, `-exec`, `-execdir`, `-ok`, `-okdir`, `-fls`, `-fprint`, `-fprintf`, `-ls`, `-print` and `-printf`". In fact, `-mtime` is not an action. – rickhg12hs Jan 29 '23 at 10:11
-
Okay thank you so much. Maybe, I am just too much of a newbie to understand what any of that means... But, please tell me, in simple words.... Do I need `-print` with `-mtime` or not? So, I can make sense of why they are giving me the same results. Thank you so much!! – Grateful Jan 29 '23 at 10:35
-
1"-print is used by default for everything unless you have another option" -- no. `-print` is used by default unless there's another **action**. `-mtime` isn't an action, just a condition. It doesn't _do_ anything. So, as you saw, you get the printing by default when all you have is `-mtime` (or other conditions). It's different if you have `find . -mtime -30 -exec true \; -print` and remove the `-print` – ilkkachu Jan 29 '23 at 11:19
-
2@ilkkachu Finally! The penny just dropped. Thank you so much for that answer. It really helped!! – Grateful Jan 29 '23 at 11:32