InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Ubuntu tutorials

  • How to add a user on Linux with sudo access
  • How to check if a user has password on Linux
  • How to install ViewVC for svn repository on Ubuntu Linux
  • How to setup ssl (https) for your site on Ubuntu Linux
  • Install rabbitmq on Ubuntu Linux
  • LXC (Linux Containers) - quick start tutorial on Ubuntu
  • Linux - command to check swap size
  • Linux - how to add a user using useradd
  • Linux - how to create a large file like 1GB
  • Linux - how to create swap partition
  • Linux - how to remove user from a group
  • Linux - number of cpus (lscpu)
  • Linux du - find disk usage of directories or files
  • NFS client and server handy commands
  • Setup svn repository on AWS Ubuntu with apache auth
  • Ubuntu - check if a service is upstart based
  • Ubuntu - dpkg and apt-get beginner tutorial
  • Ubuntu - find file to package
  • Ubuntu - find where will a package be installed from
  • Ubuntu - how to auto start services on boot using update-rc.d (sysv init)
  • Ubuntu - how to find boot autostart status of a service
  • Ubuntu - reload iptables rules during boot
  • Use x2go to access remote Ubuntu Linux
 
  • Home
  • > Tutorials
  • > Devops

Linux – how to create a large file like 1GB

on Apr 16, 2016

Sometimes we need a large file with any content on Linux. This may be needs for benchmarking and testing purpose. Here are some ways to create large file on Linux.

Using dd

To create a 1GB file filled will nulls (zeros) using 1MB buffer

$ dd if=/dev/zero of=file.out bs=1M count=1024
To see the time taken, we can run it using time
$ time dd if=/dev/zero of=file1.out bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 14.5134 s, 74.0 MB/s

real	0m14.546s
user	0m0.000s
sys	0m0.795s

Note that instead of /dev/zero we can also use /dev/urandom top copy random numbers in data. This will be slower though.

Using fallocate

faalocate does not have to read device like dd and works much faster.

$  time fallocate -l 1G file2.out

real	0m0.001s
user	0m0.000s
sys	0m0.001s

Using truncate

Truncate is also very fast but it creates sparse file. Command du will report it as 0 disk space used file unless we use –apparent-size option.

$ time truncate -s 2G file3.out
$ du  file3.out 
0
$ du --apparent-size file3.out 
1048576	file3.out

Suggested posts:

  1. HTML – is closing li tag required?
  2. CSS clearfix – clear float automatically using ::after
  3. Linux – command to check swap size
  4. Linux file timestamps
  5. Bash shell – check if file or directory exists
  6. Bash check if file begins with a string
  7. Linux – how to run a command as different user
  8. Linux/Unix – truncate a large log file without deleting it
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Devops, Linux, Tutorials, Ubuntu Linux
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress