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

  • SEARCH
  • Home
  • 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

INFORMIX-SQL 4.1 - There's this ASCII UNIX file called passwd in /usr/informix/etc which holds
I have a file, which holds phone number data, and also some useless stuff.
Both operations create an empty file and return the filename but mkstemp leaves the
I have a php file that holds my login details named connect.php. $host =
I want to generate the xml file that holds its schema as well as
Anyone know what function or file in linux holds the algorithm that finds a
Suppose I have two lists that holds the list of source file names and
File: /home/USER/DIR/a http://www.here.is.a.hyper.link.net/ /home/USER/DIR/b http://www.here.is.another.hyper.link.net/ Need to remove all the odd lines in this
FILE *out=fopen64(text.txt,w+); unsigned int write; char *outbuf=new char[write]; //fill outbuf printf(%i\n,ftello64(out)); fwrite(outbuf,sizeof(char),write,out); printf(%i\n,write); printf(%i\n,ftello64(out));
FILE #1 (foo.h): #ifndef FOO_H_ #define FOO_H_ #include baseclass.h #include bar.h class Bar; class

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.