Find and replace in file and overwrite file doesn’t work, it empties the file

I would like to run a find and replace on an HTML file through the command line. My command looks something like this: sed -e s/STRING_TO_REPLACE/STRING_TO_REPLACE_IT/g index.html > index.html When I run this and look at the file afterward, it is empty. It deleted the contents of my file. When I run this after restoring … Read more

How do I use sudo to redirect output to a location I don’t have permission to write to? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it’s on-topic for Stack Overflow. Closed 10 months ago. Improve this question I’ve been given sudo access on one of our development RedHat linux boxes, and I seem to find myself … Read more

How to redirect and append both standard output and standard error to a file with Bash

To redirect standard output to a truncated file in Bash, I know to use: cmd > file.txt To redirect standard output in Bash, appending to a file, I know to use: cmd >> file.txt To redirect both standard output and standard error to a truncated file, I know to use: cmd &> file.txt How do … Read more