Windows PowerShell Add-Content equivalent in Linux
Adds new text to the end of an existing file without replacing its current contents.
PowerShell Add-Content
printf "%s
" "text" | tee -a file.txt
printf "%s
" "text" | tee -a file.txt
printf "%s
" "text" | tee -a file.txt
Overview
What this command does
On Windows, "PowerShell Add-Content" is used to append content to a file. On Linux, the closest practical mapping shown here is "printf "%s " "text" | tee -a file.txt". Adds new text to the end of an existing file without replacing its current contents. This reference is grouped under PowerShell Equivalents → File System.
Windows → Linux context
What changes when you use this on Linux?
Equivalent task, different tool
Windows PowerShell Add-Content maps to printf "%s
" "text" | tee -a 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.
For the broader concept behind this mapping, read PowerShell vs Bash.
Practical tasks
Common use cases
Append content to a file
Adds new text to the end of an existing file without replacing its current contents.
printf "%s\n" "new line" >> notes.txt
Append using shell redirection
printf "%s\n" "new line" | tee -a notes.txt
Append and display the text
printf "%s\n" "option=yes" | sudo tee -a /etc/example.conf
Append to a protected file
Ready to run
Copyable Linux commands
Review paths, device names, package names and permissions before running any command.
printf "%s\n" "new line" >> notes.txt
printf "%s\n" "new line" | tee -a notes.txt
printf "%s\n" "option=yes" | sudo tee -a /etc/example.conf
Walkthrough
Examples with explanations
printf "%s\n" "new line" >> notes.txt # append one line
printf "%s\n" "new line" | tee -a notes.txt # append while echoing output
printf "%s\n" "option=yes" | sudo tee -a /etc/example.conf # append with root privileges
Reference
Common options and variations
| Command or option | Use |
|---|---|
printf "%s\n" "new line" >> notes.txt | Append using shell redirection |
printf "%s\n" "new line" | tee -a notes.txt | Append and display the text |
printf "%s\n" "option=yes" | sudo tee -a /etc/example.conf | Append to a protected file |
Distro differences
Debian/Ubuntu vs Fedora vs Arch
Debian/Ubuntu, Fedora and Arch all use "printf "%s " "text" | tee -a 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.
| Distribution | Package manager / base | Equivalent command | Difference to notice |
|---|---|---|---|
| Debian/Ubuntu | same command | printf "%s
" "text" | tee -a file.txt |
Same command on this distribution. |
| Fedora | same command | printf "%s
" "text" | tee -a file.txt |
Same command on this distribution. |
| Arch | same command | printf "%s
" "text" | tee -a file.txt |
Same command on this distribution. |
Keep learning