I want to append this text:
<Directory "/var/www/*">
Order allow,deny
Allow from all
AllowOverride All
</Directory>
to the file /etc/apache2/apache2.conf
I have access via SSH but I don't know how to use VIM. I would like to do this via a command.
This syntax is called "HERE documents":
This solution is better than using ctrl-d since it can be used inside shell scripts.
Use:
(you may need to use
sudo
)This will give you a command line text editor that works much like normal text editors. Use the arrow keys to navigate. Backspace, enter, etc. work as normal.
To save, press Ctrl+O and use Ctrl+X to exit. For help, press Ctrl+G from inside nano, or use
man nano
.It should look something like this:
Here's an easy way to do it, using
cat
.You terminate your input with the CTRL-D .
This takes interactive input from
cat
(i.e., whatever you type in), and appends it to the existing filetestf
.testf
(with two original lines intact) will now look like this:As other answers have illustrated, you will need special syntax when editing files which you don't have write permission on. I find it easier to just switch to the root user for this, i.e.,
sudo su
. But another easy method is to usetee
with the append flag set, and called withsudo
:sudo tee -a >> config.conf
The
nano
editor is more friendly (sudo apt-get install nano
if not available).Since you asked for a Vim, here is the command to run:
If you don't have
vim
, this is also equivalent to eithervi -e
orex
.Alternative cleaner approach:
Just run the first line (without
$
), paste the multi line text, then typeEOF
to finish.