Windows
Linux
PowerShell Equivalents
File System
Windows PowerShell Add-Content equivalent in Linux
Adds new text to the end of an existing file without replacing its current contents.
Windows
→
PowerShell Add-Content
Linux equivalents
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
Adds new text to the end of an existing file without replacing its current contents.
Migration tip: Use
>> for normal shell appends. Use sudo tee -a when appending to a file that requires elevated privileges.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
This command is the same on Debian/Ubuntu, Fedora and Arch Linux when the relevant tool is installed.
| 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