How to Create a File of Size More Than 2Gb in Linux/Unix

How to create a file of size more than 2GB in Linux/Unix?

I can think of two possible reasons:

  • You don't have Large File Support enabled in your Linux kernel
  • Your application isn't compiled with large file support (you might need to pass gcc extra flags to tell it to use 64-bit versions of certain file I/O functions. e.g. gcc -D_FILE_OFFSET_BITS=64)

cannot write(2) file larger than 2GB (up to 2TB)

According to the man page (emphasis mine)

On Linux, write() (and similar system calls) will transfer at most 0x7ffff000 (2,147,479,552) bytes, returning the number of bytes actually transferred. (This is true on both 32-bit and 64-bit systems.)

How to create a file with a given size in Linux?

For small files:

dd if=/dev/zero of=upload_test bs=file_size count=1

Where file_size is the size of your test file in bytes.

For big files:

dd if=/dev/zero of=upload_test bs=1M count=size_in_megabytes

Create a large file with a given size with a pattern in Linux

while true ; do printf "DEADBEEF"; done | dd of=/tmp/bigfile bs=blocksize count=size iflag=fullblock

Need to find a file with size more than 1GB with extension of file type

It seems that you are searching for files OVER 1GB in size which will exclude any files equalling 1GB in size

find /home/test -type f -size +1G -and -regex '\(.*tar\|.*gzip\|.*zip\|.*tgz\)'

To attain files that are equal to 1GB and above, use something like:

find /home/test -type f -size +999M -and -regex '\(.*tar\|.*gzip\|.*zip\|.*tgz\)'

If you need more accuracy, use c for bytes or k for kilobytes when specifying size.



Related Topics



Leave a reply



Submit