• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero® Blog

NameHero® Blog

Web Hosting Tips & Resources From NameHero

  • AI Agents
    • OpenClaw
    • Claude Code
    • n8n
    • Hermes Agent
    • Open WebUI
    • Docker
  • Hosting
    • Web Hosting
    • WordPress Hosting
    • WooCommerce Hosting
    • Enterprise Hosting
    • Email Hosting
    • HeroicGuard
    • GPU Hosting
    • Website Builder
  • VPS
    • Managed VPS
    • Unmanaged VPS
    • Flex VPS
  • Reseller
  • Gaming
  • Domains
  • Account
  • Blog Home
  • Categories
  • Authors

The Fallocate Linux Command, And How To Use It To Quickly Create Files For Testing

CJ Saathoff

Published on: August 22, 2024

Categories: Linux Command Line 0

Have you required a test file or files of a specific size? How about needing to quickly allocate space? If so my first recommendation is the fallocate command. In this blog post, we will explore this command, how it differs from other options, and what else it can do.

Table of Contents
  • Introduction
  • Basic Syntax
  • Considerations
  • Flags
  • Examples
  • Alternative Methods
  • Conclusion
  • My Other Posts

Introduction

The fallocate command is part of the Linux util-linux package. This is pre-installed on most standard Linux Distributions. It is most commonly used to quickly create blank files. It allows you to pre-allocate space to both preexisting files and create new files while allocating space.

Basic Syntax

The basic syntax of the command is as follows:

fallocate [options] filepath

Considerations

  • Files created with the fallocate command are empty files that contain no real data. Though what it creates is not random, if you need truly random files this is not the tool for you.
  • Not all file systems support fallocate, though if you stick with a commonly used Linux file system this shouldn’t come up.
  • ⚠️ Warning: If you have to use fallocate on exiting files make sure to make a backup before you do in case you need to revert the change.

Flags

Here are the flags I think you will find most useful will be most useful:

-c, --collapse-range remove a range from the file
 -d, --dig-holes      detect zeroes and replace them with holes
 -i, --insert-range   insert a hole at range, shifting existing data
 -l, --length <num>   length of the file (also referred to as size) in bytes unless provided with another unit of size
 -n, --keep-size      prevent file length modification
 -o, --offset <num>   offset for range operations, assumed to be a byte range unless otherwise specified
 -p, --punch-hole     replace a range with a hole (implies -n)
 -z, --zero-range     zero and ensure allocation of a range
 -v, --verbose        verbose mode

If you’re not seeing something here you think it should be able to do please check with the –help flag or refer to the manual page.

Examples

  1. Create a 100MB File:fallocate -l 100M newfileThis command creates a new file named newfile and allocates 100MB of disk space to it. As you can see we specified the length in MB rather than specifying length bytes
  2. Make an existing file the size of 1Gfallocate -l 1G existingfileThis command pre-allocates 1G to an existing file without changing the contents. The allocated disk space will now show up under ls for this file.
  3. Allocate space to a file keeping file sizefallocate -n -l 10M existingfileThis will preallocate space of 10M of disk space for existing file without the size shown by ls changing.
  4. Allocate Space with an Offset:fallocate -o 2M -l 100M newfileBy using the length and offset arguments this command allocates 100MB of disk space for newfile, the specified range starting at an offset of 2MB.
  5. Zero a Range in a File:fallocate -z -o 5000000 -l 10000000 existingfileThis command zeroes out a 10000000 byte range in existingfile, starting from an offset of 5000000. It should be noted that the byte range starting at 5000000 is equal to 5MB and the length bytes is equal to 10MB.

Alternative Methods

It should be noted that there are alternative methods for creating files for testing. They go about this in different ways so if fallocate doesn’t appear quite what you’re looking for please research other methods before making your decision.

Some of these alternative tools are listed below.

  • truncate
  • head
  • tail
  • dd

Conclusion

In this post, we have answered what the fallocate command is. This pre-installed command is most commonly used to quickly create files for testing. Though that isn’t all we will explore everything from Syntax, Considerations, Flags, Examples, and more. In this blog post, we will explore this command, how it differs from other options, and what else it can do.

My Other Posts

Are you done reading and looking for additional material, why not check out my other posts?

CJ Saathoff

Embracing a lifelong passion for technology since childhood, CJ delved into the intricate workings of systems, captivated by the desire to understand the unknown. This innate curiosity led to his discovery of Linux, a revelation that resonated deeply. With more than 7 years of on the job experience, he’s honed his technical skills as a Geek and Senior Linux Systems Administrator.

Related Posts

When to Use Here-String vs Heredoc in Bash

Heredoc and Here-string are both ways to input strings into commands that read from stdin. Here's the difference between them.

How to Use Dig to Specify a DNS Server

Dig is a Linux tool that allows you to query nameservers. It also allows you to query specify nameservers for debugging.

Dealing with Cron Job Logs in Linux

Cron job logs keep track of which cron jobs run, and their details. This helps with troubleshooting and performance management.

How to Use Git Rebase Interactive to Manage Commits

As a project progresses, commits can get messy. The git rebase interactive feature allows you to keep a clean commit history.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!


Most Popular Posts

NameHero’s Recommended WordPress Plugin and Theme Setup

WordPress Hosting vs. Web Hosting – What’s The Difference?

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • WordPress Tutorials
  • OpenClaw Hosting
  • Enterprise Hosting
  • WooCommerce
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • Website Performance
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero® proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • Managed VPS Hosting
  • Unmanaged VPS Hosting
  • Flex VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • GPU Hosting
  • Email Hosting
  • HeroicGuard
  • Domains
  • Website Builder
  • AI Agent Hosting
Help & Support
  • NameHero Blog
  • NameHero Gaming Blog
  • Support
  • Help Center
  • Migrations
  • Affiliates
  • Gaming Affiliates
  • Call 1-855-984-6263
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2026 Name Hero, LLC. All rights reserved.
NameHero® is a registered trademark.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA