← All commands
Topic hub PowerShell Equivalents
Windows Linux PowerShell Equivalents Expanded guide File System

Windows PowerShell Set-Content equivalent in Linux

Writes new content to a file, replacing the previous contents.

Windows PowerShell Set-Content
→
Linux equivalents
Debian/Ubuntu same command
printf "%s " "text" > file.txt
Fedora same command
printf "%s " "text" > file.txt
Arch same command
printf "%s " "text" > file.txt

Overview

What this command does

On Windows, "PowerShell Set-Content" is used to replace file contents. On Linux, the closest practical mapping shown here is "printf "%s " "text" > file.txt". Writes new content to a file, replacing the previous contents. This reference is grouped under PowerShell Equivalents → File System.

Migration tip: Shell redirection with <code>&gt;</code> replaces a file. <code>tee</code> is useful when the destination requires sudo permissions.

Windows → Linux context

What changes when you use this on Linux?

Equivalent task, different tool

Windows PowerShell Set-Content maps to printf "%s " "text" > file.txt for this task. Treat this as a workflow mapping rather than a character-for-character syntax translation.

Portable across the compared distros

The Debian/Ubuntu, Fedora and Arch rows use the same command in this mapping. Package availability or defaults can still vary, so check the installed tool version when an option behaves differently.

Command-specific caution

The > operator truncates the destination before writing. Use >> or tee -a when you intend to append.

Practical tasks

Common use cases

Replace file contents

Writes new content to a file, replacing the previous contents.

printf "%s\n" "Hello" > file.txt

Replace a file with one line

printf "%s\n" "one" "two" > file.txt

Write multiple lines

printf "%s\n" "setting=value" | sudo tee /etc/example.conf

Write a root-owned file

Ready to run

Copyable Linux commands

Review paths, device names, package names and permissions before running any command.

printf "%s\n" "Hello" > file.txt
printf "%s\n" "one" "two" > file.txt
printf "%s\n" "setting=value" | sudo tee /etc/example.conf

Walkthrough

Examples with explanations

printf "%s\n" "Hello" > file.txt # replace the file contents
printf "%s\n" "one" "two" > file.txt # write several lines
printf "%s\n" "setting=value" | sudo tee /etc/example.conf # write through sudo

Reference

Common options and variations

Command or optionUse
printf "%s\n" "Hello" > file.txtReplace a file with one line
printf "%s\n" "one" "two" > file.txtWrite multiple lines
printf "%s\n" "setting=value" | sudo tee /etc/example.confWrite a root-owned file

Distro differences

Debian/Ubuntu vs Fedora vs Arch

Debian/Ubuntu, Fedora and Arch all use "printf "%s " "text" > file.txt" for this mapping. The command syntax shown here is portable across the three rows, although installed versions and system defaults can still vary.

DistributionPackage manager / baseEquivalent commandDifference to notice
Debian/Ubuntu same command printf "%s " "text" > file.txt Same command on this distribution.
Fedora same command printf "%s " "text" > file.txt Same command on this distribution.
Arch same command printf "%s " "text" > file.txt Same command on this distribution.

Important

What to watch out for

The > operator truncates the destination before writing. Use >> or tee -a when you intend to append.

Keep learning

Related PowerShell Equivalents commands