Answer the question
In order to leave comments, you need to log in
Chown and chmod for a lot of files?
Hello everyone, there is Apache on the server and a bunch of folders with root rights ~ 1,200,000 folders and 1 file in each. Everything is on Amazon aws, linux ubuntu. Since the disk itself is 22GB, the number of stored files per unit of memory has been increased. The file system is ext4, inode_ratio = 4096 , which makes it possible to store ~ 6,000,000 inodes per 22GB.
Task: all 2,400,000 files need to be given chown www-data.www-data and chmod 0755
I do: sudo chown www-data.www-data -R dir/
as a result, 15 minutes pass and I can only set the owner for 600,000 files , but Kopal does not go further
in the internet, I found some xargs -p and find . I can not link them, tell me who knows how to installchown only for files that are currently root and also chmod 0755 for files that are not
. Something like this ( don't use this example, it's not valid )
find -user root dir/ | xargs -p chown www-data.www-data -R dir/
find -permissions -rw-r--r-- dir/ | xargs -p chmod 0755 -R dir/
UPDATE:
important detail - all folders are numbered from 1 to 1,200,000 and have the following structure 1/file.txt
ANSWER
Thanks for the help Aves and fomistoklus !!!
For this task, I could not find a solution from the already implemented tools. They may work, but I couldn't verify it. A script was written to solve the problem:
#!/bin/bash
echo "run it"
filename=/var/www/html/counter.txt
current=0
max=0
lim=0
cnt=1
totalcount=1
while read -r string
do
for word in $string; do
if [ "$cnt" -eq "1" ]
then current=$word
elif [ "$cnt" -eq "2" ]
then max=$word
else
lim=$word
fi
cnt=$((cnt+1))
done
done < "$filename"
echo "$current"
echo "$max"
echo "$lim"
while [ "$current" -le "$max" ]
do
if [ -d /var/www/html/questions/"$current"/ ]; then
cd /var/www/html/questions/"$current"/
find . ! -perm 0755 -exec chmod 0755 {} \;
find . ! -user www-data -exec chown www-data.www-data {} \;
totalcount=$((totalcount+1))
fi
echo "loop"
current=$((current+1))
if [ "$totalcount" -gt "$lim" ]
then break
fi
done
echo "$current $max $lim"
echo "$current $max $lim" > /var/www/html/counter.txt
cd /var/www/html/
1 1150022 60
*/1 * * * * /var/www/html/script.sh >/dev/null 2>/dev/null
364 1151860 60
- after 5 minutes Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question