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 have a complex setup with two systems running on two computers with shared space.

One of the systems downloads large files and creates symlinks in the shared space. The other system (a windows system) thinks that there is not space left.

What I would like to do is to limit the size of files in one folder in linux. In other words, the directory (and sub-directories) will only contain files up to say 1MB. Anything larger than that will be disregarded. Can that be done?

thanks.

share|improve this question
    
You already have a process that creates the symlinks from the downloaded files to the directory. Can't you modify that process so that it doesn't create a link if the filesize is too large? –  cjc Nov 6 '12 at 20:42

3 Answers 3

up vote 2 down vote accepted

I'm affraid that it's possible to set the maximum file size limit for the whole system only (for each and every file).

ulimit -f <size_in_blocks>

You might also limit the total size of a directory by mounting the directory from the virtual filesystem (a file):

dd if=/dev/zero of=~/disk_image count=<size_in_blocks>
mkfs -t ext3 ~/disk_image
mount -o loop=/dev/loop0 ~/disk_image <directory>
share|improve this answer

Another method I thought of would be to schedule a cronjob to run on the linux machine every minute or at an interval of your choosing that executes a script that looks for any files greater than 1M and either removes them or moves them to another directory for review.

For the script, look into using 'find'

man find

An example:

find /home/user/storage -type f -size +1M

This would look through the /home/user/storage directory and locate files greater than 1MB. You can also add -exec to the line to perform actions on the files found.

share|improve this answer
2  
Instead of doing that, you may want to consider inotify, particularly the incrontab facility. It will watch the directory for I/O, so no need for a messy cron job. –  cjc Nov 6 '12 at 20:40
    
That's not a bad idea either cjc, I should have thought of that :) –  bmurtagh Nov 6 '12 at 22:49

You can use a product called quota it seems to be preinstalled on Red Hat.

check the following links

http://souptonuts.sourceforge.net/quota_tutorial.html http://www.yolinux.com/TUTORIALS/LinuxTutorialQuotas.html

I have never actually administered this myself, however I have worked on systems that have had this installed and it seems to work.

Let me know how you get along

James

share|improve this answer

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.