I have a small program and I want to ensure that it works on both write protected files and un-write protected files. So, instead of using
echo $text > $file or
echo $text >> $file, I am instead forced to use
echo $text | sudo tee $file and
echo $text | sudo tee --append $file, respectively. When I use
sudo tee, even if I change the permissions, whenever I use
rm on the file, it prompts me like so:
$ ls someFile writeProtectedFile $ rm someFile $ ls writeProtectedFile $ rm writeProtectedFile rm remove write-protected regular file 'writeProtectedFile'? yes $ ls
I then poked around on the web, looking for possible solutions to my dilemma. There were only two out there that I could find: incorrect permissions, or a changed set of permissions. I knew the permissions case to be incorrect, because I could easily change the permissions by running
sudo chmod xxx filename, which would result in a successful permissions change. I assumed then that there was a problem with the file attributes, so I ran
lsattr on the file and it would output
-------------e--, same as every other file in the directory.
The reason I was using
tee was to echo text to write protected files, but as a side effect it also write protected regular files... My goal was to, in effect, do something like
sudo echo "whatever" >> /etc/someFile, which does not work, so I found a solution in
echo "whatever" | sudo tee /etc/someFile.