0

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?

9
  • 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. Commented Jan 29, 2023 at 9: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? Commented Jan 29, 2023 at 9:50
  • 1
    From 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." Commented Jan 29, 2023 at 9:58
  • 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 Commented Jan 29, 2023 at 11:19
  • 2
    @ilkkachu Finally! The penny just dropped. Thank you so much for that answer. It really helped!! Commented Jan 29, 2023 at 11:32

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.