Skip to content
Advertisement

Trying to find empty files in other user home directory

I want to search for empty files inside the home directory of the user “adam” for example.

Now i don’t know the right path for that user, so I need to get it from /etc/passwd with the following command:

grep ^adam: /etc/passwd | cut -d: -f6

Output: /home/adam (for example) Then executing this command to find the empty files.

find /home/adam -type f -size 0 -print

Is it possible to do this with one command?

So I tried this:

grep ^adam: /etc/passwd | cut -d: -f6 | find -type f -size 0 -print

Advertisement

Answer

Very close … this is what I’d do (using one command instead of two):

find $(awk -F: '$1=="adam"{print $6}' /etc/passwd) -type f -size 0

(Thanks for the improvement suggestion, Ed)

With your grep & cut this would work, too:

find $(grep ^adam: /etc/passwd | cut -d: -f6) -type f -size 0

These two are using command substitution

If you prefer a pipe you could use xargs:

grep ^adam: /etc/passwd | cut -d: -f6 | xargs -i find "{}" -type f -size 0
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement