Fighting root
The sysadmin at my former employer had the bad habit of uploading files as root to directories we all used. It was a real PITA, so I hacked this script to fix the perms, without having to be root. No magic: the directory has to be writable.
#!/bin/bash## Wed Nov 23 19:25:14 CET 2005 * <nonick AT 8027 DOT org>## Aarggh....#################### Load lib#if [ ! -f ~/bin/messages.sh ]; thenecho "~/bin/messages.sh is required but not found. Bye..."exit 1fi. ~/bin/messages.sh################### Check params#if (( ${#@} < 1 ))thenechoecho $(basename $0)echoecho " Looks for files owned by root and moves and copies them to regain ownership"echo " This needs the target directory to be writable by the user"echoecho " Usage:"echo " $0 <directory>"echoexit 1fidir=$1if [ ! -d "$dir" ] || [ ! -w "$dir" ]thenerror_msg "Error: either '$dir' is not a directory or it is not writable."exit 2fi################### Go#info_msg "\nRegaining ownership of files in directory '${BLUE}$dir${OFF}'...\n\n"for file in $(find $dir -name '*php')dogroup=$(stat -c %g $file)cnt=0if (( group == 0 ))thenrun_cmd "File ${RED}${file}${OFF} belongs to root, moving ... "\"mv $file $file~~ && cp $file~~ $file"let cnt=$cnt+1fidoneinfo_msg "\n${BLUE}${cnt}${OFF} files needed moving.\n\n"if (( cnt > 0 ))thenif ask_msg "I left backup files. Remove them? " "N"then#run_cmd "Removing ... " "find $dir -iname '*php~~' -exec rm \{\} \;"info_msg "${RED}Feature disabled${OFF}\n\n"fifiexit 0;- Download this code: findrootfiles.sh

