Shell Script – Check file owner and other attributes

Here is a simple shell script which would read a user input and return you the owner and group of the input path.


echo "Please enter a file/folder path:"
read target_path
echo "You have entered $target_path"

if [ -e $target_path ]; then
  target_owner=$(stat -c %U $target_path)
  target_group=$(stat -c %G $target_path)

  echo "$target_path owner is: $target_owner"
  echo "$target_path group is: $target_group"
  echo "$target_path is not a valid path"


Try it out.

Done =)



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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