chown
is great if you are a superuser. I had an issue where someone else had run make
in my directory, and now owned some files that I could not modify. Here is my workaround which handles files and directories, although it leaves the directories lying around with suffix .mkmeowner
if it can't delete them.
- The following script changes ownership of files and directories passed to it to be owned by the current user,
attempting to work around permission issues
by making a new copy of every directory or file
not owned by the current user, deleting (or trying to delete)
the original file, and renaming appropriately.
- The intent is for it to be an abbreviation for "make me owner". I don't use underscores because they are a pain to type.
Examples:
% mkmeowner .
% mkmeowner dirpath1 dirpath2
- It requires the following script
mkmeownerone
to be in your path.
mkmeowner:
#!/bin/bash
[ "x$1" == "x-h" ] || [ "x$1" == "x--help" ] && cat << END && exit 0
Usage: $0 dirorfile [direorfile2 ...]:
change ownership of directories or files to current user.
Current user must have permissions to read those and write to owner directory.
END
mkmeownerone=`which mkmeownerone`
for d in $*; do
find "$d" -not -user `whoami` -exec $mkmeownerone {} \;
done
mkmeownerone:
#!/bin/bash
# change ownership of one file or directory
f="$1"
expr match "${f}" '.*\.mkmeowner$' > /dev/null && exit 1 # already tried to do this one
if mv -f "$f" "${f}.mkmeowner"; then
cp -pr "${f}.mkmeowner" "$f" && rm -rf "${f}.mkmeowner"
exit 0
fi
exit 1
man chown
andman chmod
easily answer your question. – Shi – 2012-08-15T21:08:18.7703
@Shi I think it's a fair question. Reading that man page wouldn't help. Globbing is not part of
– djf – 2012-08-15T21:27:11.133chmod
. It is builtin to the shell. Also reading documentation on globbing sucks the life out of you (I spent way to much time figuring out all the zsh's features).1@djf:
chown -R user:group .
– Shi – 2012-08-16T20:05:49.227