A book about the command line for humans.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
6.1 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. 8. the command line and the web
  2. ===============================
  3. Web browsers are really complicated these days. They're full of rendering
  4. engines, audio and video players, programming languages, development tools,
  5. databases --- you name it, and there's a fair chance it's in there somewhere.
  6. The modern web browser is kitchen sink software, and to make matters worse, it
  7. is _totally surrounded_ by technobabble. It can take _years_ to come to terms
  8. with the ocean of words about web stuff and sort out the meaningful ones from
  9. the snake oil and bureaucratic mysticism.
  10. All of which can make the web itself seem like a really complicated landscape,
  11. and obscure the simplicity of its basic design, which is this:
  12. Some programs pass text around to one another.
  13. Which might sound familiar.
  14. The gist of it is that the web is made out of URLs, "Uniform Resource
  15. Locators", which are paths to things. If you squint, these look kind of like
  16. paths to files on your filesystem. When you visit a URL in your browser, it
  17. asks a server for a certain path, and the server gives it back some text. When
  18. you click a button to submit a form, your browser sends some text to the server
  19. and waits to see what it says back. The text that gets passed around is
  20. (usually) written in a language with particular significance to web browsers,
  21. but if you look at it directly, it's a format that humans can understand.
  22. Let's illustrate this. I've written a really simple web page that lives at
  23. [`http://p1k3.com/hello_world.html`](http://p1k3.com/hello_world.html).
  24. $ curl 'https://p1k3.com/hello_world.html'
  25. <html>
  26. <head>
  27. <title>hello, world</title>
  28. </head>
  29. <body>
  30. <h1>hi everybody</h1>
  31. <p>How are things?</p>
  32. </body>
  33. </html>
  34. `curl` is a program with lots and lots of features --- it too is a little bit
  35. of a kitchen sink --- but it has one core purpose, which is to grab things from
  36. URLs and spit them back out. It's a little bit like `cat` for things that live
  37. on the web. Try the above command with just about any URL you can think of,
  38. and you'll probably get _something_ back. Let's try this book:
  39. $ curl 'https://p1k3.com/userland-book/' | head
  40. <!DOCTYPE html>
  41. <html lang=en>
  42. <head>
  43. <meta charset="utf-8">
  44. <title>userland: a book about the command line for humans</title>
  45. <link rel=stylesheet href="userland.css" />
  46. <script src="js/jquery.js" type="text/javascript"></script>
  47. </head>
  48. <body>
  49. `hello_world.html` and `userland-book` are both written in HyperText Markup
  50. Language. HTML is just text with a specific kind of structure. It's been
  51. around for quite a while now, and has grown up a lot in 20 years, but at heart
  52. it still looks a lot [like it did in 1991][www].
  53. The basic idea is that the contents of a web page are marked up with tags.
  54. A tag looks like this:
  55. <title>hi!</title> -,
  56. | | |
  57. | `- content |
  58. | `- closing tag
  59. `-opening tag
  60. Sometimes you'll see tags with what are known as "attributes":
  61. <a href="https://p1k3.com/userland-book">userland</a>
  62. This is how links are written in HTML. `href="..."` tells the browser where to
  63. go when the user clicks on "[userland](http://p1k3.com/userland-book)".
  64. Tags are a way to describe not so much what something _looks like_ as what
  65. something _means_. Browsers are, in large part, big collections of knowledge
  66. about the meanings of tags and ways to represent those meanings.
  67. While the browser you use day-to-day has (probably) a graphical interface and
  68. does all sorts of things impossible to render in a terminal, some of the
  69. earliest web browsers were entirely text-based, and text-mode browsers still
  70. exist. Lynx, which originated at the University of Kansas in the early 1990s,
  71. is still actively maintained:
  72. $ lynx -dump 'http://p1k3.com/userland-book/' | head
  73. userland
  74. __________________________________________________________________
  75. [1]# a book about the command line for humans
  76. Late last year, [2]a side trip into text utilities got me thinking
  77. about how much my writing habits depend on the Linux command line. This
  78. struck me as a good hook for talking about the tools I use every day
  79. with an audience of mixed technical background.
  80. If you invoke Lynx without any options, it'll start up in interactive mode, and
  81. you can navigate between links with the arrow keys. `lynx -dump` spits a
  82. rendered version of a page to standard output, with links annotated in square
  83. brackets and printed as footnotes. Another useful option here is `-listonly`,
  84. which will print just the list of links contained within a page:
  85. $ lynx -dump -listonly 'http://p1k3.com/userland-book/' | head
  86. References
  87. 2. http://p1k3.com/2013/8/4
  88. 3. http://p1k3.com/userland-book.git
  89. 4. https://github.com/brennen/userland-book
  90. 5. http://p1k3.com/userland-book/
  91. 6. https://twitter.com/brennen
  92. 9. http://p1k3.com/userland-book/#a-book-about-the-command-line-for-humans
  93. 10. http://p1k3.com/userland-book/#copying
  94. An alternative to Lynx is w3m, which copes a little more gracefully with the
  95. complexities of modern web layout.
  96. $ w3m -dump 'http://p1k3.com/userland-book/' | head
  97. userland
  98. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  99. # a book about the command line for humans
  100. Late last year, a side trip into text utilities got me thinking about how much
  101. my writing habits depend on the Linux command line. This struck me as a good
  102. hook for talking about the tools I use every day with an audience of mixed
  103. technical background.
  104. Neither of these tools can easily replace enormously capable applications like
  105. Chrome or Firefox, but they have their place in the toolbox, and help to
  106. demonstrate how the web is built (in part) on principles we've already seen at
  107. work.