Skip to content

Instantly share code, notes, and snippets.

@ryu1
Last active December 21, 2020 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryu1/7e1e98a0c47603c80891ec59636d2e75 to your computer and use it in GitHub Desktop.
Save ryu1/7e1e98a0c47603c80891ec59636d2e75 to your computer and use it in GitHub Desktop.
There are shellscripts for changing ower of files or directories..
#/bin/bash
# Finds the object with the specified group ID and changes the owning group.
# _gid : Group ID that remains unchanged
# _grp : Group name you want to change
find_gid_and_chown_group() {
_gid=${1}
_grp=${2}
_buf_ifs=${IFS}
IFS=
find / -gid ${_gid} -print | \
while read _path
do
if [ -d ${_path} -o -f ${_path} ]; then
# Change the ownership group of directories and files
echo "Change ${_path}"
chown .${_grp} ${_path}
elif [ -h ${_path} ]; then
# Change the owning group of the symbolic link itself
echo "Change ${_path}"
chown -h .${_grp} ${_path}
else
echo "No Change ${_path}"
fi
done
IFS=${_buf_ifs}
}
find_gid_and_chown_group $1 $2
#/bin/bash
# Finds the object with the specified user ID and changes the owning user.
# _uid : User ID that remains unchanged
# _usr : Username you want to change
find_uid_and_chown_user() {
_uid=${1}
_usr=${2}
_buf_ifs=${IFS}
IFS=
find / -uid ${_uid} -print | \
while read _path
do
if [ -d ${_path} -o -f ${_path} ]; then
# Change the owner user of directories and files
echo "Change ${_path}"
chown ${_usr} ${_path}
elif [ -h ${_path} ]; then
# Change the owning user of the symbolic link itself
echo "Change ${_path}"
chown -h ${_usr} ${_path}
else
echo "No Change ${_path}"
fi
done
IFS=${_buf_ifs}
}
find_uid_and_chown_user $1 $2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment