Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4070078
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:34:54+00:00 2026-05-20T16:34:54+00:00

File holes are the empty spaces in file, which, however, doesn’t take up any

  • 0

File holes are the empty spaces in file, which, however, doesn’t take up any disk space and contains null bytes. Therefore, the file size is larger than its actual size on disk.

However, I don’t know how to create a file with file holes for experimenting with.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T16:34:55+00:00Added an answer on May 20, 2026 at 4:34 pm

    Use the dd command with a seek parameter.

    dd if=/dev/urandom bs=4096 count=2 of=file_with_holes
    dd if=/dev/urandom bs=4096 seek=7 count=2 of=file_with_holes
    

    That creates for you a file with a nice hole from byte 8192 to byte 28671.

    Here’s an example, demonstrating that indeed the file has holes in it (the ls -s command tells you how many disk blocks are being used by a file):

    $ dd if=/dev/urandom bs=4096 count=2 of=fwh # fwh = file with holes
    2+0 records in
    2+0 records out
    8192 bytes (8.2 kB) copied, 0.00195565 s, 4.2 MB/s
    
    $ dd if=/dev/urandom seek=7 bs=4096 count=2 of=fwh
    2+0 records in
    2+0 records out
    8192 bytes (8.2 kB) copied, 0.00152742 s, 5.4 MB/s
    
    $ dd if=/dev/zero bs=4096 count=9 of=fwnh # fwnh = file with no holes
    9+0 records in
    9+0 records out
    36864 bytes (37 kB) copied, 0.000510568 s, 72.2 MB/s
    
    $ ls -ls fw*
    16 -rw-rw-r-- 1 hopper hopper 36864 Mar 15 10:25 fwh
    36 -rw-rw-r-- 1 hopper hopper 36864 Mar 15 10:29 fwnh
    

    As you can see, the file with holes takes up fewer disk blocks, despite being the same size.

    If you want a program that does it, here it is:

    #include <unistd.h>
    #include <sys/types.h>
    #include <stdio.h>
    #include <fcntl.h>
    
    int main(int argc, const char *argv[])
    {
        char random_garbage[8192]; /* Don't even bother to initialize */
        int fd = -1;
        if (argc < 2) {
            fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
            return 1;
        }
        fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0666);
        if (fd < 0) {
            perror("Can't open file: ");
            return 2;
        }
        write(fd, random_garbage, 8192);
        lseek(fd, 5 * 4096, SEEK_CUR);
        write(fd, random_garbage, 8192);
        close(fd);
        return 0;
    }
    

    The above should work on any Unix. Someone else replied with a nice alternative method that is very Linux specific. I highlight it here because it’s a method distinct from the two I gave, and can be used to put holes in existing files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think the file that is produced is an .asm file, any idea how
I have a CSV file that holds about 200,000 - 300,000 records. Most of
File formats I would like to play include .wav, .mp3, .midi. I have tried
File is sent to the client using Response.writefile and content diposition as inline. When
In file Atomic.aiml, part of the annotated ALICE AIML files , there are a
Good file comparison tools were already discussed to the pain, but my problem is
The .XFDL file extension identifies XFDL Formatted Document files. These belong to the XML-based
How can I check file permissions , without having to run operating system specific
I have an actionscript file that defines a class that I would like to
Given a (source) patch file, what's the easiest way to apply this patch on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.