Search code examples
linuxfind

find: paths must precede expression: `days'


Hi maybe a noob question here. I am running the command

find . -atime -2 days # n = 2

to see the files accessed 2 days ago. But the shell returns an error saying

find: paths must precede expression: days'`

I am using Ubuntu 20 LTS and cannot seem to understand the issue

I used the commands from here. And this but cannot seem to solve my issue.

Help would be appreciated. Thanks.


Solution

  • The immediate problem is that -atime -2 days is interpreted as the option -atime with the value -2 and a path for find to search, which is an error because the paths need to be before the predicates on the command line.

    The immediate fix is to remove "days" entirely, since the value for -atime is already expressed in units of days (or, strictly speaking, periods of 86400 seconds).

    Some other commands allow you to express suffixes to indicate periods of time, but find is not one of them; but even then, they have to be quoted as a single argument. For example, date -d "2 days" (not date -d 2 days; and note that the -d option is a GNU extension, and not portable).

    Unfortunately, the world wide web is saturated with "computer help" pages with syntax errors or worse, especially around shell scripting. If you find that an example doesn't work, probably consult the manual page for the utility you are trying to use.