This repository has been archived on 2024-03-04. You can view files and clone it, but cannot push or open issues or pull requests.
linux/.linux/bash/module/own.sh

24 lines
454 B
Bash
Raw Normal View History

2023-08-08 16:24:15 +03:00
# change file ownership to specified user id and restrict access to him.
2023-10-30 03:49:10 +03:00
# usage: own [USER] [FILES]
2023-08-08 16:24:15 +03:00
own()
{
2023-10-29 18:27:32 +03:00
local file="${2}"
local user="${1}"
2023-08-08 16:24:15 +03:00
# default to current dir.
2023-10-29 18:27:32 +03:00
if [ "${file}" = "" ]; then
2023-08-08 16:24:15 +03:00
file='.'
fi
# default to current user.
2023-10-29 18:27:32 +03:00
if [ "${user}" = "" ]; then
user="${UID}"
2023-08-08 16:24:15 +03:00
fi
# set ownership.
2023-10-29 18:27:32 +03:00
chown "${user}":"${user}" -R "${file}" &> /dev/null
2023-08-08 16:24:15 +03:00
# remove access from group and others.
2023-10-29 18:27:32 +03:00
chmod -077 -R "${file}"
2023-08-08 16:24:15 +03:00
}