Quantcast
Channel: Eureka! » Shell Script
Viewing all articles
Browse latest Browse all 14

Shell Script – Check file owner and other attributes

$
0
0

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

check_owner_and_group.sh

#!/bin/sh

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"
else
  echo "$target_path is not a valid path"
fi

 

Try it out.
shell-script-check-file-owner-and-group
 

Done =)

Reference:


Filed under: Shell Script Tagged: Linux, Shell Script

Viewing all articles
Browse latest Browse all 14

Trending Articles