07-27-2023, 11:51 AM
So today, April 23rd 2015, the Internet Assigned Numbers Authority had decreed the use of [port 6379](
I wish to com·mem·o·rate this splendid occasion by adding the following line to my `/etc/services` file:
redis 6379/tcp
What would be the best way to go about it? By best I mean, of course, the following:
1. Needless to say, the new line should be inserted in its proper place (i.e.g. under the Assigned Numbers block, right after `gnutella-rtr 6347/udp` on my system)
2. I've considered the use of various text editors, but it feels out of place
3. Ideally, the solution should be a copy-pastable one-liner
4. I can envision the `awk` script that could do that but I'm looking for something more, a certain je ne sais quoi
*Update re @Markus' `sed` proposal:* I'm afraid the problem would be applying this "patch" on other systems that do not necessarily have the same `/etc/services` file so, expanding on point #1 above, the solution must ensure that regardless the specifics of to-be-preceding service in the file, order is kept.
*Update 2:* a few points that seem important to state - a) while not mandatory, the solution's length (or lack of rather) is certainly an important part of its elegance (similarly for external dependencies [i.e. lack of these]); b) I/we assumed that `/etc/services` is sorted, but it would be interesting to see what happens when it isn't; c) assume that you have root privileges and be careful with that `rm / -rf` command.
[To see links please register here]
) to [Redis]([To see links please register here]
), a frabjous day indeed!I wish to com·mem·o·rate this splendid occasion by adding the following line to my `/etc/services` file:
redis 6379/tcp
What would be the best way to go about it? By best I mean, of course, the following:
1. Needless to say, the new line should be inserted in its proper place (i.e.g. under the Assigned Numbers block, right after `gnutella-rtr 6347/udp` on my system)
2. I've considered the use of various text editors, but it feels out of place
3. Ideally, the solution should be a copy-pastable one-liner
4. I can envision the `awk` script that could do that but I'm looking for something more, a certain je ne sais quoi
*Update re @Markus' `sed` proposal:* I'm afraid the problem would be applying this "patch" on other systems that do not necessarily have the same `/etc/services` file so, expanding on point #1 above, the solution must ensure that regardless the specifics of to-be-preceding service in the file, order is kept.
*Update 2:* a few points that seem important to state - a) while not mandatory, the solution's length (or lack of rather) is certainly an important part of its elegance (similarly for external dependencies [i.e. lack of these]); b) I/we assumed that `/etc/services` is sorted, but it would be interesting to see what happens when it isn't; c) assume that you have root privileges and be careful with that `rm / -rf` command.