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/.config/bash/module/own.sh

23 lines
446 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-12-07 01:44:42 +03:00
function own() {
2023-12-05 21:50:45 +03:00
local file="${2}"
local user="${1}"
2023-08-08 16:24:15 +03:00
2023-12-05 21:50:45 +03:00
# default to current dir.
if [ "${file}" = "" ]; then
file='.'
fi
2023-08-08 16:24:15 +03:00
2023-12-05 21:50:45 +03:00
# default to current user.
if [ "${user}" = "" ]; then
user="${UID}"
fi
2023-08-08 16:24:15 +03:00
2023-12-05 21:50:45 +03:00
# set ownership.
chown "${user}":"${user}" -R "${file}" &> /dev/null
2023-08-08 16:24:15 +03:00
2023-12-05 21:50:45 +03:00
# remove access from group and others.
chmod -077 -R "${file}"
2023-08-08 16:24:15 +03:00
}