Solved

Limit file size allowed to be created at directory level

Posted on 2004-10-11
20
227 Views
Last Modified: 2013-12-06
Hi Guys,
Is there a way one can limit the file size one can create at directory level
Example: I don't want people/processes to be able to create files larger than 5MB in usr/home/admin   directory.


Any advice appreciated


Cheers


B Cunney
0
Comment
Question by:Barry Cunney
  • 9
  • 4
  • 3
  • +1
20 Comments
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 12277718
You can't limit the size of individual files, but you can limit the total disk space used by a given user in a given filesystem by using disk quotas. See the quota man-page and the various pages it points to on your system.
0
 
LVL 2

Expert Comment

by:Troxalias
ID: 12284256
You don't mention which OS you are usingbut probably " uname -f " will do the job.
For example uname -f 10000 will set the limit you want. Be careful that when setting file size limit the number specified referres to 512 byte blocks.
0
 
LVL 17

Author Comment

by:Barry Cunney
ID: 12285021
Hi Troxalias,
This is AIX Version 5.2.0.0


Cheers


B Cunney
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 17

Author Comment

by:Barry Cunney
ID: 12285061
Hi Troxalias,
uname on AIX seems to be a command to display machine information??
0
 
LVL 17

Author Comment

by:Barry Cunney
ID: 12285063
                    Commands Reference, Volume 5, s - u

uname Command

Purpose

Displays the name of the current operating system.

Syntax

uname [ -a | -x | -SName ] | [ -l ] [ -L ] [ -m ] [ -M ] [ -n ] [ -p ] [ -r ] [
-s ] [ -TName ] [ -u ] [ -v ]

Description

The uname command writes to standard output the name of the operating system
that you are using.
0
 
LVL 2

Expert Comment

by:Troxalias
ID: 12285065
Hi B Cunney,

Not familiar with AIX. However in both Solaris and HP-UX this works. Give a try on a user shell. It is completely harmless! Check your settings with uname -a .
0
 
LVL 2

Expert Comment

by:Troxalias
ID: 12285074
Oh, Sorry!!!!!! Wrong command! I meant, ulimit !!! Replace uname with ulimit ;-)
Sorry again, very bad headache today!
0
 
LVL 17

Author Comment

by:Barry Cunney
ID: 12285101
No worries Troxalias - bad headaches are allowed - we all have 'bad headache' days - I got mine out of the way yesterday  
0
 
LVL 17

Author Comment

by:Barry Cunney
ID: 12285136
Can this command be used to set a limit  on size files that can be created in a specific directory?
0
 
LVL 2

Expert Comment

by:Troxalias
ID: 12285732
hmmm... i have never tried it, but i don't think that it would be possible... As fas as i am concerned you cannot do it with this command. It is a somehow user-oriented command...
0
 
LVL 14

Accepted Solution

by:
chris_calabrese earned 25 total points
ID: 12286540
Ulimit sets the limit on a given process plus its children. It can be put in /etc/profile and similar places to put a limit on the size of a file a given user can create, but it is global and doesn't apply to any particular directory or filesystem.

The closest you can likely get is to make the directory in question its own filesystem and then set quotas on that filesystem. This won't limit the size of an individual file, but it will limit the total file space per user in that filesystem.
0
 
LVL 17

Author Comment

by:Barry Cunney
ID: 12286759
Thanks for the feedback
...but I was hoping there was some way to restrict the size of file that could be created in a specified directory
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 12302425
ulimit will do the trick as long as the users cannot get out their shell, for example with cron (there you have to take care for ulimit settings again).

  ulimit -H -f 5000000

in /etc/profile, or

  limit -h filesize 5000000

in /etc/csh.cshrc (and /etc/csh.login)

# both suggestions assuming standard sh, bash, ksh, pdksh, ash, csh, tcsh, tsh, zsh, lsh, etc. etc. setup
0
 
LVL 17

Author Comment

by:Barry Cunney
ID: 12306255
Hi Ahoffmann,
but how do I set this up so it only relates to one specific directiory - maybe I am misunderstanding you.

I only want this to be applied to a single directory - usr/home/admin
I just want to set something up so as no user can create a file of larger than 5MB in a single directory, namely usr/home/admin.

??
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 12311653
> but how do I set this up so it only relates to one specific directiory
impossible with limit/ulimit, see comments above. You need quota for that, or ACLs.

> ..  so as no user can create a file of larger than 5MB in a single directory ..
not precise enough:
  do you mean that *each* user  cannot create *any* file > 5MB anywhere
or
  *each* user cannot create *any* file > 5MB in /usr/home/admin

 
0
 
LVL 17

Author Comment

by:Barry Cunney
ID: 12317187
Hi ahoffmann,

*each* user cannot create *any* file > 5MB in /usr/home/admin


Cheers
0
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 25 total points
ID: 12317722
you need quota or acls, as already said
0
 
LVL 17

Author Comment

by:Barry Cunney
ID: 12531312
Hi jmcg,
That is fine - happy to split the points between the 2 guys, Chris and ahoffman


Cheers


B Cunney
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
AIX Server 10 84
AIX  NFS  question 1 136
Generate FIPS 140-2 Public Key on Unix 5 74
Access_log 17 118
Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now