0

When i specify user in on the find function on the terminal: Why do I have to write a / before I write -user EXAMPLE?

example:

find -user USERNAME

won't do anything whereas

find / -user USERNAME

Work exactly as intended?

P.S: If I use 2 functions one after the other:

find / -user USERNAME -group GROUPNAME

Will it find the files that are belong to both user and the group or files that belong to the user or the group?

I tried searching on the documentation for answers and couldn't find anything, where can I find answers for this type of questions?

Ganja
  • 1

2 Answers2

1

Given that you are using Linux, you are likely using GNU find. That supplies a "." (current working directory) if no explicit directory parameter is given.

The find utility only shows what it finds (does not actually tell you where it is looking), so you may not have noticed this. Apparently there is nothing in (or under) your current working directory owned by USERNAME, but there is on the computer. When you gave it a "/" as parameter, find searched through the whole computer, starting at the root-level "/".

Regarding

find / -user USERNAME -group GROUPNAME

find treats it as if you said

find / \( -user USERNAME -a -group GROUPNAME \)

POSIX explains it like this:

Conjunction of primaries; the AND operator is implied by the juxtaposition of two primaries or made explicit by the optional -a operator. The second expression shall not be evaluated if the first expression is false.

In your command, these are primaries:

-user USERNAME
-group GROUPNAME

Further reading:

Thomas Dickey
  • 76,765
0

So, the syntax is

find (starting directory) (actions and flags)

So, You need to specify some directory even if it is just the / directory. It does not default to /

Example:

find /starting_dir -size +500 -atime +20 -print

This would start in starting_dir and look for all files that use 500 blocks or more not accessed in the last 20 days

Klamz
  • 35
  • 1
  • 6