[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] tee: add a -q/--quiet option
From: |
Fabrice BAUZAC |
Subject: |
Re: [PATCH] tee: add a -q/--quiet option |
Date: |
Sat, 26 Dec 2020 18:16:25 +0100 |
Pádraig Brady <P@draigBrady.com> writes:
> On 24/12/2020 06:01, Alex Henrie wrote:
>> It is very useful to be able to read a file as root and then process
>> it as an ordinary user, for example:
>> sudo cat protected.txt | grep foo
>> However, there is currently no exact equivalent for the opposite:
>> Generating text as a normal user and writing it to a file as
>> root. `tee` is commonly used for this purpose:
>> echo foo | sudo tee protected.txt
>> The downside is that tee always prints to standard output in addition
>> to writing to the file. This can be avoided with piping, but it makes
>> the command quite cumbersome:
>> echo foo | sudo tee protected.txt > /dev/null
Why not
echo foo | sudo sh -c "exec cat > protected.txt"
or
echo foo | sudo dd of=protected.txt status=none
>> I propose adding a -q/--quiet flag to `tee` which causes it to only
>> write to the specified files and not to stdout. This would allow the
>> following convenient command to be used for writing to a protected
>> file: echo foo | sudo tee -q protected.txt
>> This would be a GNU extension. Happy holidays!
If something is really needed, I would suggest an option to "cat" rather
than "tee":
echo foo | sudo cat --output=protected.txt
echo foo | sudo cat -oprotected.txt
--
Fabrice BAUZAC-STEHLY
PGP 015AE9B25DCB0511D200A75DE5674DEA514C891D