• Uncategorized

About linux : How-to-check-if-linux-user-has-sh-file

Question Detail

I have to write script in bash that will check if logged users have any .sh files.
Checking who is logged in is simple just using:

w| awk '{print $1}'

But i have no idea how to check if they havy any .sh files

Question Answer

You need to read the output of the who command and use that in your find command.

Since the same user can be logged in multiple times, it’s a good idea to remove duplicates before looping.

who| awk '{print $1}' | sort -u | while read -r username; do
    find /home/"$username" -name "*.sh"

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.