To create an empty file in Linux, run touch filename for a true zero-byte file or use shell redirection with > filename to truncate an existing file to nothing. These two commands are the standard answer on every distribution and require no extra packages. Beyond the textbook answer, Linux actually exposes at least six reliable paths to a zero-byte or exact-size empty file, and the right choice depends on whether you care about the inode, the on-disk allocation, the size in bytes, or the content. A file can also be logically empty yet still consume space through filesystem allocation blocks. For most developers, touch and > filename cover everyday needs. When the test environment demands a file of a specific byte count, commands like truncate, fallocate, and dd take over. And when the goal is to reproduce an exact-size empty file across any operating system without touching a terminal, a browser-based generator that runs locally is worth knowing about.

how to create empty file in linux
How to Create an Empty File in Linux Step by Step

Six Linux Commands That Create an Empty File

Every mainstream Linux distribution ships the commands below in coreutils or in the shell itself, so no installation is required. They differ in subtle ways that matter once a script, a CI pipeline, or a test suite starts depending on them.

  • touch filename creates a regular file with no content if it does not exist; otherwise it only updates the access and modification timestamps. The resulting file is a true zero-byte file occupying one inode but no data blocks.
  • > filename is shell redirection that creates the file if missing and truncates it to zero bytes if it already exists. Faster than touch when the file is large because it does not reallocate blocks gradually.
  • : > filename produces the same outcome as > filename, but the leading colon makes intent explicit and avoids the shell error you would get from a stray redirect that lost its command.
  • echo -n > filename or printf '' > filename are useful when you want a quoted empty string for clarity in scripts, though the resulting file is still zero bytes.
  • truncate -s 0 filename sets the file size to exactly zero bytes and creates the file if it does not exist. By default this produces a sparse file, which reports zero bytes yet allocates almost no disk blocks until something writes to it.
  • dd if=/dev/null of=filename reads from /dev/null, writes nothing, and creates a regular zero-byte file. Slightly slower than touch but it is the fallback when nothing else is available, including minimal containers.

All six options above produce a file that stat reports as zero bytes. They differ in how the disk allocation is handled and how they behave when the file already exists.

Specifying an Exact Byte Size in Linux

Sometimes "empty" actually means "exactly N bytes." For an upload validator that accepts only files in a narrow range, a checksum pipeline that hashes a fixed-length blob, or a download progress indicator that needs to render a specific percentage, the byte count has to match exactly.

CommandResulting fileNotes
truncate -s N fileSparse by default; reports N bytesUse --no-create if the file must exist first. Combined with -s, a sparse file is the default.
fallocate -l N fileFully allocated; no real zeros writtenFastest for large sizes because the kernel reserves space without filling it.
dd if=/dev/zero of=file bs=1 count=NFully allocated and filled with 0x00Slowest but produces a file whose actual bytes are all zeros, which matters for compression and hash tests.
head -c N /dev/zero > fileFully allocated and filled with 0x00Convenient shorthand for the dd line above.

The MiB-to-byte math matters here. The boundary 50 MiB equals 50 × 1024 × 1024 = 52,428,800 bytes, which is also the largest dummy file the browser tool described below accepts. Pick truncate, fallocate, or dd based on whether you want sparse or fully allocated space, then keep the same command in production that you used in development so the on-disk behaviour matches.

How to Create an Empty File in Linux

  1. Open a terminal in the directory where you want the file, or cd into it.
  2. Run touch newfile.txt to create a regular zero-byte file. Replace newfile.txt with any name your filesystem accepts, avoiding slashes and reserved device names such as NUL or COM1.
  3. Confirm the size with stat newfile.txt or wc -c newfile.txt. Both should report 0 for a true empty file.
  4. If you need a file of a specific byte size, replace step 2 with truncate -s 52428800 newfile.bin, fallocate -l 52428800 newfile.bin, or dd if=/dev/zero of=newfile.bin bs=1 count=52428800.
  5. Re-check with stat --format=%s newfile.bin to confirm the byte count matches what you asked for.
  6. Use the file as needed for upload tests, attachment validation, progress indicators, or checksum pipelines.

For scripts, prefer : > "$path" or truncate -s 0 "$path" because both behave predictably when the file already exists and when noclobber is set in the shell.

When a Browser-Based Tool Is the Better Fit

Shell commands are the right answer when you are already logged into a Linux server, a CI runner, or a container. They become awkward when you need to hand a colleague on macOS or Windows the same exact-size file, when you want to test a web upload form without keeping a Linux VM handy, or when you do not want to install utilities like fallocate on a stripped-down container. A browser tool that generates the file locally avoids those steps and keeps the bytes inside the current tab.

The Dummy File Generator builds a Blob in memory, verifies its size against the requested value, and offers a normal download link. Construction and downloading happen in the current browser tab; nothing is uploaded to a backend. The tool accepts a safe file name, a whole-number byte size from 1 through 52,428,800 bytes (exactly 50 MiB), and a content mode chosen from zero bytes, secure random bytes, or repeated UTF-8 text.

Generate an Exact-Size Empty File in the Browser

  1. Open the Dummy File Generator in any modern browser.
  2. Enter a safe file name such as test-50mb.bin. The tool rejects empty names, leading or trailing whitespace, dot paths, path separators, control characters, and Windows device names such as CON and NUL.
  3. Enter the exact whole-number byte size. The smallest file is one byte and the largest accepted value is exactly 52,428,800 bytes. The size field accepts digits only, with no sign, no decimal point, no unit suffix, and no surrounding whitespace.
  4. Pick a content mode:
    • Zero bytes writes only byte value 0x00 across the entire file using bounded Uint8Array parts. This is the closest match to an empty file that still has a non-zero byte count.
    • Secure random bytes uses the browser's Crypto.getRandomValues API in chunks of at most 65,536 bytes, which is the API boundary. The result is incompressible and ideal for checksum tests.
    • Repeated UTF-8 text encodes a pattern you provide with TextEncoder and repeats it toward the requested byte count. If only a partial character fits at the end, the tool pads with ASCII spaces so the file remains valid UTF-8.
  5. Click Generate, confirm the displayed byte summary and the disclosed content policy, then click the download link. The Blob is verified to match the requested size before it is published, so a file that says "52,428,800 bytes" on screen is exactly 52,428,800 bytes on disk.

Because the bytes are produced in the browser and the download link is a local ObjectURL, no bytes, file name, or text pattern are sent to a backend service. Closing or editing the page revokes the URL, so regenerate the file if you need it again.

Choosing Between Shell Methods and the Browser Tool

Use the comparison below to pick a default for your team without re-reading every section.

ScenarioBest fitReason
Quick placeholder file on a Linux servertouch or > fileFastest, zero dependencies, returns a true zero-byte file.
File of an exact byte count for an upload limittruncate -s N or dd if=/dev/zeroPredictable, scriptable, and reproducible across Linux hosts.
Incompressible data for checksum testsdd if=/dev/urandom bs=1 count=N or browser random modeBoth produce non-repeating bytes; the shell version is reproducible only by re-running the command.
Cross-platform sample without a terminalBrowser toolWorks on Windows and macOS, generates locally, and avoids installing coreutils.
File whose extension is for naming only, not formatBrowser tool with zero modeA .png or .pdf download name does not produce a real image or PDF; it is just a name with zero or repeated bytes inside.
Files larger than 50 MiBShell commandsThe browser tool caps the requested size at exactly 52,428,800 bytes; shell commands scale with available disk space.

A practical rule of thumb: pick the shell for live servers, CI runners, and any workflow that already calls coreutils, and pick the browser tool when you need a portable artifact, an offline build, or a file whose exact size and content policy you want to verify by reading a summary on screen before downloading.