Solved

Limit file size allowed to be created at directory level

Posted on 2004-10-11
20
225 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
Comment Utility
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
Comment Utility
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
Comment Utility
Hi Troxalias,
This is AIX Version 5.2.0.0


Cheers


B Cunney
0
 
LVL 17

Author Comment

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

Author Comment

by:Barry Cunney
Comment Utility
                    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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Can this command be used to set a limit  on size files that can be created in a specific directory?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Expert Comment

by:Troxalias
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
> 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
Comment Utility
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
Comment Utility
you need quota or acls, as already said
0
 
LVL 17

Author Comment

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


Cheers


B Cunney
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

728 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