I would like to be able to insert the contents of a text file at the end of the host file.
I need that because my hosts file is frequently updated.
How can I do that?
Thanks.
I would like to be able to insert the contents of a text file at the end of the host file.
I need that because my hosts file is frequently updated.
How can I do that?
Thanks.
Ubuntu Mate 18.04 Bionic and Ubuntu Mate 20.04
Mate Desktop
Appends the contents of file1 to the bottom of file2. The double redirection (">>") means append. With only one redirection character (">") file2 would overwritten.Code:cat file1 >> file2
Last edited by SeijiSensei; April 7th, 2021 at 12:55 AM.
If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.
Blog · Linode System Administration Guides · Android Apps for Ubuntu Users
It does not work because it is root owned.
I tried
Code:echo xx | sudo -S cat AddTo_hosts.txt >> /etc/hosts
Last edited by raleigh3; April 7th, 2021 at 03:45 AM.
Ubuntu Mate 18.04 Bionic and Ubuntu Mate 20.04
Mate Desktop
What you need is for the part of the operation that writes to the file (not necessarily the part that reads from a file) to be run with elevated privileges.
Something likeorCode:echo 'xxx' | sudo tee -a /etc/hostsYou can stick aCode:cat AddTo_hosts.txt | sudo tee -a /etc/hostson the end if you don't want the text that you're piping around to also be displayed on your terminal.Code:> /dev/null
Last edited by CatKiller; April 7th, 2021 at 06:20 AM.
Thanks CatKiller.
Ubuntu Mate 18.04 Bionic and Ubuntu Mate 20.04
Mate Desktop
Bookmarks