Find the answer to your Linux question:
Results 1 to 7 of 7
If I have a file in which data is written which leads to the increase of this file size Is it possible to make a constraint such that this file ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2011
    Posts
    2

    how to make constraints on the size of any file


    If I have a file in which data is written which leads to the increase of this file size
    Is it possible to make a constraint such that this file size mustn't exceed certain size
    let say 5 MB for instance

    Thanks in advance

  2. #2
    Linux Guru
    Join Date
    Oct 2007
    Location
    Tucson AZ
    Posts
    3,190
    The site below gives an explanation of how to do this:

    File size limit exceeded error under Linux and solution

  3. #3
    Linux Enthusiast Mudgen's Avatar
    Join Date
    Feb 2007
    Location
    Virginia
    Posts
    664
    limits.conf fsize sets limits per user, per group, or globally for _any_ file, not specific files. Although the thread title says "any file", the OP seems to want to apply specific files. I don't know the answer.

  4. #4
    Just Joined!
    Join Date
    Jun 2011
    Posts
    2
    actually yes it not for all files it's for certain files
    so you are telling me here that it can be done for user or group so how can this be done
    for certain user ? or certain group ?

  5. #5
    Linux Enthusiast Mudgen's Avatar
    Join Date
    Feb 2007
    Location
    Virginia
    Posts
    664
    I'm saying that the link Yancek posted does _not_ show how to do it for specific files, only globally for all files. Maybe he'll check back in with more help.

  6. #6
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
    Posts
    1,283
    Hi.

    More information would be useful.

    What do you think should happen if a file exceeds the specified size? Abort, exit gracefully, fill up another file, rotate among n files (keeping the last n), etc.?

    One way you can do it is to create a filesytem of a certain size. For testing I often have:
    Code:
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/md2              7.6M  1.1M  6.1M  15% /small
    So if you are using LVM that is fairly easy.

    Another way is to require the use of a filter (that you would write) that does something when the limit is reached:
    Code:
    ./a.out | my-size-limit 5M
    Best wishes ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  7. #7
    Just Joined!
    Join Date
    Sep 2010
    Location
    Dhaka, Bangladesh
    Posts
    29
    I don't know whether this will help, but it's worth checking

    http://sarmed-quota.blogspot.com


    7. Set quota for user Harry so that when user Harry types dd=/dev/zero of=file bs=1024K count=4 he succeeds, but when he types dd=/dev/zero of=file bs=1024K count=8 he fails.
    The command dd=/dev/zero of=file bs=1024K count=4 creates a file that is 4KB in size. Count=8 creates a 8KB file. So, we have to define quota so that soft limit is 4KB and hard limit is 8KB.
    Because we have to define quota for a user, we have to implement quota to the partition containing his home directory. If there is no /home partition, we implement quota in / partition.
    #df –h //to find out the partition containing /home

    vim /etc/fstab

    /dev/hdaX /home ext3 defaults,quota 0 0
    add


    #mount -o remount //remounts all the partitions;-o==options

    #quotacheck -cM /home //-c==check, -M==modify

    #quotaon /home

    #edquota Harry //edit quota for user Harry….all information here is in kilobytes

    partition blocks soft hard inode soft hard
    /dev/hdaX do not edit 4096 8192 do not edit do not edit do not edit

    #repquota -v /home //report quota verbosely for /home
    OR
    #repquota –va //reports all existing quotas

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •