Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I've been working on a back up script for a client, however if I get the size via FTP account, it takes a long time to load the page, was wondering if running a SSH command via PHP would be much quicker? Could anyone tell me what commands would I need to use to determine a folder size in kb?

OR

To get a user quota used? as I have a FTP user for each backup account, so just need to know how much it's using

share|improve this question

2 Answers 2

This will give you the size in kb for each home-dir in /home:

for username in `ls /home/`
do
    echo "Size for is $username `du -hs /home/$username/ --block-size=1024 | cut -f1`kb"
done    

If you have a list somewhere of the ftp-users, you could modify this script to use that list by putting that into the for-loop.

for username in `awk -F: '{print $1}' /home/mylistwithusers`
share|improve this answer
    
Could you tell me how I would get a file size in KB for a folder in /home/backuos/user1/ ? As can't figure out how to format this.. Thanks! –  Saulius Antanavicius May 15 '12 at 18:21
    
@SauliusAntanavicius That would be: du -s /home/backuos/user1/* --block-size=1024 or du -s /home/backuos/* --block-size=1024. Your question is a bit ambiguous. Hope that helps! –  Bart De Vos May 15 '12 at 22:25
    
oen last question, your commands print out every directories size in the folder, how can I just get back the size for the whole thing? I tried using -c but it still includes all of the other folders.. it works if I navigate to the directory and run du -s but then I need to navigate to it and I don't wan't to do that every time.. Would appreciate the help! –  Saulius Antanavicius May 17 '12 at 12:11
1  
Achieved it with du -sh /home/backups/13/* --block-size=1024 | awk '{total=total+$1} END {print total}' –  Saulius Antanavicius May 17 '12 at 12:26

Couldn't you just use the filesize() function in PHP recursively to get the entire directory size?

share|improve this answer
    
I already said this takes to long to load because of that! –  Saulius Antanavicius May 15 '12 at 18:17
    
"however if I get the size via FTP account" makes it sound like you logged into an FTP server to get the size... if the directory is on the server itself, it could be quick. –  Taylor Jasko May 15 '12 at 21:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.