Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm using | sudo tee FILENAME to be able to write or append to a file for which superuser permissions are required quite often.

Although I understand why it is helpful in some situation, that tee also sends its input to STDOUT again, I never ever actually used that part of tee for anything useful. In most situations, this feature only causes my screen to be filled with unwanted jitter, if I don't go the extra step and manually silence it with tee 1> /dev/null.

My question: Is there is a command arround, which does exactly the same thing as tee, but does by default not output anything to STDOUT?

share|improve this question
    
If you replace the tee with cat >filename, do you get the results that you want? –  sawdust Nov 11 '12 at 23:12
    
cat does not write to files by itself. And the > operator doesn't work as the files are not writable by my current user. So no, that doesn't help a bit. And please stop to completely alter your comment's meaning every 2 seconds. Make a new one instead. –  aef Nov 11 '12 at 23:14
    
If you replace the | sudo tee FILENAME with | sudo cat >filename, do you get the results that you want? –  sawdust Nov 11 '12 at 23:20
    
No, the > operator uses the current shell user to write to the file. This user hasn't got the neccessary permissions. cat is completely useless for that. –  aef Nov 11 '12 at 23:23
    
Also see stackoverflow.com/questions/82256/… –  Joachim Breitner Apr 26 '13 at 8:10
add comment

3 Answers

up vote 1 down vote accepted

Another option that avoids piping the stuff back and then to /dev/zero is

sudo command | sudo dd of=FILENAME
share|improve this answer
    
Exactly what I was looking for. Great thanks. –  aef Sep 7 '13 at 14:36
add comment

You could use a script. I.e. put something like this in i.e. $HOME/bin/stee, 0tee or similar:

#!/bin/bash

argv=
while [[ "$1" =~ ^- ]]; do
    argv+=" $1"
    shift
done

sudo tee $argv "$1" > /dev/null

#!/bin/bash

sudo tee "$@" > /dev/null

Make it executeable:

$ chmod 755 stee

Now do i.e.:

$ ls -la | stee -a /root/foo

share|improve this answer
    
Writing a script and deploying it to all the systems I work on is not exactly what I wanted, but until someone names an already existing tool, I think I'll go with your solution. –  aef Nov 12 '12 at 0:07
1  
Indeed. Would like to see it myself. I wrote a program in C a long time back that did what you ask, but it is a long time gone and forgotten. There was close to no interest for it back when. But then again I did not actually advertise it much. –  Luca Stein Nov 12 '12 at 17:59
add comment

There is not directly a program to do that (this is pretty much the only time that it would be useful), but you could easily write your own. If you do not want to program, you could also write a simple shell script that does the same thing: cat > $1. This is different from putting it inline (as sawdust suggested) because the sudo will apply to the entire script, including the redirection.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.