Archive

Archive for May, 2011

write to file in linux

May 20th, 2011 1 comment

If you want to write to a file in linux you can do the following:

echo "something" > /var/log/test.log

but if the test.log file is only writable by root, then you have to use sudo. 

sudo echo "semothing" > /var/log/test.log

but this also fails because it is only echo that is running as sudo not the actual writing to file.

The way I do this is my using the tee command:

echo 'something' | sudo tee /var/log/test.log

You could also do:

echo "echo 'something' > /var/log/test.log" | sudo sh

but that seems more hacky….

Categories: Uncategorized Tags: