Skip to content

Instantly share code, notes, and snippets.

@coltenkrauter
Created September 11, 2022 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coltenkrauter/eb0dbb4804857ebd8eeecce8f7177cc2 to your computer and use it in GitHub Desktop.
Save coltenkrauter/eb0dbb4804857ebd8eeecce8f7177cc2 to your computer and use it in GitHub Desktop.
Bash/sh/zsh one liners, append to a file with sudo
# 1. One liner, append to a file
echo "A new line at the end of the file" >> file.txt
# 2. One liner, append to a file including newlines
echo -e "\n\nA new line at the end of the file that is preceeded by some new lines" >> file.txt
# 3. One liner, append to a file the requires sudo
echo "A new line at the end of the file that requires sudo" | sudo tee -a /etc/fstab
---
Related
# 4. Overwrite a file
echo "A new line at the end of the file" > file.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment