0

I am trying to set the limit on files to be 10GB across the entire system. When ulimit -f is run, I get back unlimited.

When ulimit -a is run, I see that the units of file size are blocks. How do these convert to bytes?

1

In Bash, by default 1024 bytes, but 512 bytes in POSIX mode (manual):

If no option is given, then -f is assumed. Values are in 1024-byte increments, except [some others] and, when in POSIX Mode (see Bash POSIX Mode), -c and -f, which are in 512-byte increments.

(POSIX, of course, demands 512 byte blocks.)

$ bash -c 'ulimit -Sf 1000; 
    head -c1024000 < /dev/zero > /tmp/test && echo ok;
    echo x >> /tmp/test && echo ok'
ok
File size limit exceeded
-1

You can check /proc/partitions to see number of blocks in a given partition and use lsblk or df to check the size of the partition in bytes. The number of bytes devided by blocks will give the bytesize of a block.

For example, on my desktop:

$ cat /proc/partitions
major minor  #blocks  name

   8        0  312571224 sda
   8        1  308392960 sda1
   8        2          1 sda2
   8        5    4175872 sda5
  11        0      19930 sr0
   8       16  244198584 sdb
km0@mkdisplay:~$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 298.1G  0 disk
├─sda1   8:1    0 294.1G  0 part /
├─sda2   8:2    0     1K  0 part
└─sda5   8:5    0     4G  0 part [SWAP]
sdb      8:16   0 232.9G  0 disk
sr0     11:0    1  19.5M  0 rom
$ python
Python 2.7.13 |Anaconda, Inc.| (default, Sep 22 2017, 00:47:24)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 298.1*1024*1024*1024/312571224.
1024.03040701661
  • that doesn't have anything to do with what ulimit considers a block – ilkkachu Dec 18 '17 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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