Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

fallocate

Reserve disk space for a file at once (no data is written), or punch holes into a file.

Niveau
Dagelijks Linux
Groep
Schijven en bestandssystemen
Root nodig
Nee
Pakket
util-linux

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

fallocate -l 1G FILE creates a 1 GiB file in a moment: the file system reserves the blocks without writing zeros. Great for test files and disk-full tests. Other modes remove ranges (punch holes) or find and free zero blocks (-d).

Zo schrijf je het

fallocate [-c|-p|-z] [-o OFFSET] -l LENGTH [-n] FILE
fallocate -d [-o OFFSET] [-l LENGTH] FILE
fallocate -x [-o OFFSET] -l LENGTH FILE

Opties 12

Meest gebruikt

-l, --length LENGTH
Size, like 500M or 2G.
-o, --offset OFFSET
Start position.
-n, --keep-size
Do not change the visible file size.
-p, --punch-hole
Free the blocks of a range (the file keeps its size).
-d, --dig-holes
Find blocks with only zeros and free them.
-z, --zero-range
Make a range zeros.
-c, --collapse-range
Remove a range and move the rest up.
-i, --insert-range
Insert a hole and move the rest down.
-x, --posix
Use the POSIX way (writes zeros; slow).
-v, --verbose
Verbose.
-h, --help
Show help.
-V, --version
Show the version.

Voorbeelden 10

$ als gewone gebruiker# als root (of met sudo)

  1. 1Create a 1 GiB file at once

    fallocate -l 1G /var/tmp/test.img
    ls -lh /var/tmp/test.img

    Done in milliseconds.

  2. 2Fill a disk for a test

    fallocate -l 9G /data/fill

    Test alerts and app behaviour on a full disk; delete it after.

  3. 3Make a sparse file smaller on disk

    fallocate -d disk.img

    Zero blocks are freed (VM images, backups).

  4. 4Free a range in a log file

    fallocate -p -o 0 -l 100M big.log

    The file keeps its size, uses less disk.

  5. 5Reserve space without changing the size

    fallocate -n -l 500M db.dat

    Space is reserved for later writes.

  6. 6Compare used and visible size

    du -h --apparent-size disk.img; du -h disk.img

    After -d the real use is smaller.

  7. 7Swap file (careful)

    fallocate -l 1G /swapfile

    Works on many file systems, but swapon may refuse it; dd is the safe way.

  8. 8Test file for upload limits

    fallocate -l 101M /tmp/too-big.bin

    Test a 100 MB upload limit of a web app.

  9. 9Truncate is different

    truncate -s 1G sparse.img

    truncate makes a sparse file (no blocks reserved).

  10. 10Check quota limits

    fallocate -l 2G ~/quota-test

    Fails with "Disk quota exceeded" when the limit is lower.

Exitcodes

0 :: Done. 1 :: Error.

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man fallocate