What does `tee` do and how do you write to a root-owned file with `sudo`?
IntermediateConceptArguments, I/O, here-docs, process substitution and subshells
Answer
tee copies stdin to stdout and to one or more files (-a appends). sudo echo x > /etc/file fails because the redirection is done by your unprivileged shell, not by sudo.
echo 'vm.max_map_count=262144' | sudo tee /etc/sysctl.d/99-es.conf >/dev/null
sudo tee -a /etc/hosts >/dev/null <<'EOF'
10.0.1.10 db.internal
EOF
More on Arguments, I/O, here-docs, process substitution and subshells
How does `getopts` work? Show a complete example.IntermediateWhat is the difference between `getopts` and `getopt`?AdvancedExplain file descriptors 0, 1 and 2 and the main redirection operators.BeginnerWhy is `cmd 2>&1 > file` different from `cmd > file 2>&1`?AdvancedWhat is a here-document, and what is the difference between `<<EOF`, `<<'EOF'` and `<<-EOF`?BeginnerWhat is a here-string (`<<<`)?Intermediate