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

31 lines
690 B
Bash

# Change file ownership to specified user id and restrict access to him.
# Root user by default. This directory recursively by default.
# Usage: own [USER] [FILES]
function own() {
local IFS=$'\n'
local files=("${@:2}")
local user="${1}"
local group="${1}"
# default to current dir.
if [ "${files[*]}" = "" ]; then
files=(".")
fi
# default to current user.
if [ "${user}" = "" ]; then
user="${UID}"
fi
# If not root, default to users group.
[[ "${user}" = 0 ]] && group="0" || group="100"
for file in "${files[@]}"; do
# set ownership.
chown "${user}":"${group}" -R "${file}" &> /dev/null
# remove access from group and others.
chmod -077 -R "${file}"
done
}