I am trying to set the limit on files to be 10GB across the entire system. When
ulimit -f is run, I get back
ulimit -a is run, I see that the units of file size are
blocks. How do these convert to bytes?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
In Bash, by default 1024 bytes, but 512 bytes in POSIX mode (manual):
If no option is given, then
-fis assumed. Values are in 1024-byte increments, except [some others] and, when in POSIX Mode (see Bash POSIX Mode),
-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
You can check
/proc/partitions to see number of blocks in a given partition and use
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