Unix Pipeline (Brian Kernighan) - Computerphile

Поделиться
HTML-код
  • Опубликовано: 12 ноя 2015
  • Just what is a pipeline in the computer science sense? We asked Computer Science guru Professor Brian Kernighan
    Why Asimov's Laws of Robotics Don't Work: • Why Asimov's Laws of R...
    Brian Kerninghan on Bell Labs: • The Factory of Ideas: ...
    Don Knuth on Email: • Why Don Knuth Doesn't ...
    Computer That Changed Everything: • Computer That Changed ...
    / computerphile
    / computer_phile
    This video was filmed and edited by Sean Riley.
    Computer Science at the University of Nottingham: bit.ly/nottscomputer
    Computerphile is a sister project to Brady Haran's Numberphile. More at www.bradyharan.com

Комментарии • 270

  • @fdk7014
    @fdk7014 8 лет назад +322

    Brian Kernighan should have his own RUclips channel, I'm sure he has many interesting UNIX and general computer history stories to share.

    • @rbrrhllngswrth
      @rbrrhllngswrth 8 лет назад +7

      That is a really excellent idea!

    • @TFCxAddict
      @TFCxAddict 8 лет назад +10

      Anyone that has used Unix before pipes existed deserved an award and I would love to see this

    • @darcy6698
      @darcy6698 Год назад

      he does

  • @xeigen2
    @xeigen2 8 лет назад +161

    Pipes are so elegant that they seem obvious and trivial. But that's often the way with great ideas!

    • @axlslak
      @axlslak 2 года назад +4

      They are neither obvious nor trivial, but they are elegant. If they seem obvious or trivial to you is because you have used them for a very long time. But most of humanity still likes something to click with mouse or finger and a progress bar. That is their expectation of computing.
      Which is very different from shell and pipes.

    • @joaoa.soares772
      @joaoa.soares772 Год назад

      @@axlslak Totally agree!

    • @melodyogonna
      @melodyogonna 7 месяцев назад

      It is the way of Ken Thompson's programs

    • @xeigen2
      @xeigen2 7 месяцев назад +3

      @@axlslak Maybe it wasn't obvious from the way I phrased it but that was the point I was making. The best ideas *seem* obvious in hindsight but they're really not, they actually took a lot of careful thought and genius to come up with.
      I'm NOT actually saying they ARE obvious or ARE trivial.

  • @trylleklovn
    @trylleklovn 8 лет назад +204

    I just love hearing Brian Kernighan talk about this stuff. There is an awesome video on youtube called "The UNIX Operating System" on AT&T Tech Channel from the 70's where a younger Brian Kernighan descripes the exact same principles of UNIX, back when they were still new and groundbreaking - I recommend that video to anyone.

    • @smjpl
      @smjpl 8 лет назад +5

      +trylleklovn Great find and thanks for sharing!

    • @ziozzot
      @ziozzot 8 лет назад

      thanks for the tip 👍

    • @TheBluMeeny
      @TheBluMeeny 8 лет назад

      +trylleklovn Wow great find, that video was awesome!

    • @PropaneWP
      @PropaneWP 8 лет назад +1

      +trylleklovn Nice. This looks cool. Syns navnet ditt er ustyrtelig morsomt av en eller annen grunn :D

    • @trylleklovn
      @trylleklovn 8 лет назад

      +PropaneWP Haha :D

  • @goyabee3200
    @goyabee3200 8 лет назад +121

    My favorite use of pipeline in my own experience was when I when I piped arecord (to create a pcm data stream from microphone input) into oggenc (to compress the pcm into a vorbis audio stream) into gpg (to encrypt the audio stream(probably should have used ssl but it worked albeit with a delay for entering the passphrase)) into netcat (to send the encrypted audio stream over a network) and on the other machine the reverse ( netcat | gpg | oggdec | aplay ) and effectively created a one-way encrypted voice-over-ip system with just a handful of popular commands.

    • @christianpetersen7591
      @christianpetersen7591 8 лет назад +27

      +John Euell You just made a lower level Skype

    • @imaginaoYouTubesoquecomarrobas
      @imaginaoYouTubesoquecomarrobas 2 года назад +3

      That's honestly wild 😂

    • @deepumali7508
      @deepumali7508 2 года назад +1

      Beautiful....

    • @MrJegerjeg
      @MrJegerjeg Месяц назад +1

      Does anyone know how to achieve the same but with a video output from an integrated webcam on a computer?

    • @uis246
      @uis246 Месяц назад

      ​@@MrJegerjeg I think you can replace arecord with ffmpeg and aplay with ffplay

  • @THB192
    @THB192 8 лет назад +23

    When I saw pipes, I fully understood the magic of unix.

    • @markfrombriz
      @markfrombriz 5 лет назад +3

      Its the genius of writing simple elegant programs that do one thing really well

  • @compu85
    @compu85 8 лет назад +15

    As a system admin I use pipelines all the time. It's so useful to take existing programs and simply string them together. It also makes developing the command / program easier since you can test each step before tacking the next operation on.

  • @dice3000
    @dice3000 8 лет назад +41

    It's the simple things like this in Unix that make the system great as a whole.

    • @LeiosLabs
      @LeiosLabs 8 лет назад +8

      +gskema Seriously, the utility of the terminal is astounding!

  • @BaseSixtyFour
    @BaseSixtyFour 8 лет назад +84

    a living legend

  • @shadowmil
    @shadowmil 8 лет назад +156

    Pipes are amazing BTW. Most people who use them take them totally for granted, including me.

    • @ihrbekommtmeinenrichtigennamen
      @ihrbekommtmeinenrichtigennamen 8 лет назад

      +Charles Miller
      The problem is that they are text-based. So you either need to do a lot of regex and parse some arbitrary garbage the other program outputs or you agree on some format like XML to pass data (which rarely happens).

    • @shadowmil
      @shadowmil 8 лет назад +20

      pipes work with all sorts of data. All the common tools assume text because most of the stuff is you want to use it with are text.

    • @ArnimSommer
      @ArnimSommer 8 лет назад

      +Charles Miller Problems arise when they aren't available...

    • @majorgnu
      @majorgnu 8 лет назад +29

      Pipes, like files, don't have the concept of "type of data."
      It's just a stream of bytes. No more, no less.

    • @AnimeTheAmv
      @AnimeTheAmv 8 лет назад

      +Charles Miller So would using "program.exe < input.in > output.out" be an extremely simple example of pipelining?

  • @Guillaurent
    @Guillaurent 8 лет назад +17

    Great vid.
    One fundamental piece of information missing in the video is that all those programs you glue together are in fact working at the same time in parallel. So if some of those are CPU hungry, it helps spread the load. And the time needed for the complete chain to complete is basically the time needed for the longest program to complete (except when you are using programs that need the whole data set to do their job, like "sort").

    • @OleTange
      @OleTange 8 лет назад +3

      +Guillaume Laurent In theory true. In practice, though, your pipeline is normally limited by a single program. So if 'A | B | C' is slow due to B being slow, then you can often speed it up by 'A | parallel --pipe B | C'

  • @DragoniteSpam
    @DragoniteSpam 8 лет назад +20

    I just realized why the | symbol is called the "pipe" o_0 Unix is awesome.

  • @TheHoaxHotel
    @TheHoaxHotel 8 лет назад +167

    It's a Unix system, I know this!

    • @lucasb3h3m0th
      @lucasb3h3m0th 5 лет назад +1

      It's Computer Science .at higher level

  • @ruthklein7838
    @ruthklein7838 4 года назад +2

    Brian -- Hello. It's Ruth Klein. I worked in Berk Tague's Dept. at Murray Hill. I may have some insight as to how Doug McIlroy's idea of streaming together programs actually got implemented. I believe it came about because of a unique characteristic of the PDP-11 machine language. Before the PDP-11, computer machine languages had specialized instructions to deal with each type of I/O device. For example, there were specialized registers and a specific machine language instruction to send output to a printer. Another set of registers and another machine language instruction would have been used if you wanted to send the same data to a disk file, etc. The PDP-11 got rid of these device dependent machine language instructions. Instead, the PDP-11 replaced these with a single READ and a single WRITE machine language instruction. The actual address of the device would have been put into a machine register used by the READ or WRITE instruction. Bottom line, this meant you could write a device independent program and, when you went to run the program, you could provide parameters as to which input and output devices to use. When DEC announced the PDP-11 computer, they hosted a presentation in NYC. I was the one sent to attend that presentation and found their new machine language method of dealing with I/O devices to be a simple and elegant design. Back at the Labs, I wrote a short memo describing DEC's new mini-computer and this simplified method of dealing with I/O devices. Two days after this memo was distributed, Doug McIlroy stopped by my office, waving the memo, and saying "Tell me more about this". I believe it was this feature of the PDP-11 design that provided the straightforward method of implementing standard input and standard output. And, linking the standard output of one program to the standard input of another program implemented the concept of the pipe.

    • @ChrisHow
      @ChrisHow Год назад

      Amazing story Ruth! Must have been exciting times! Did you have any idea at the time how durable the paradigm would be, and how we'd be taking it for granted many decades later?

  • @telesniper2
    @telesniper2 3 месяца назад +3

    You're redirecting output with a system call pipe(), which is used in the shell you're using. Your shell is the parent that instantiates the child, which is the program your executing (grep, etc). So for all you curious out there, you can do this from within your C programs, it's not just for fun on the shell.

    • @gandalfgrey91
      @gandalfgrey91 2 месяца назад

      By playing around with pids basically?

  • @hemanthkumarHere
    @hemanthkumarHere 8 лет назад +3

    The first ever programming book that got into my hands was written by Kernighan and Rithcie. Its a pleasure to learn from the pros.

  • @CaptainDangeax
    @CaptainDangeax 8 лет назад

    Always a pleasure to hear BK speak about the beauty of the Unix system.

  • @johnflano
    @johnflano 8 лет назад +36

    Very subtly placed copy of "The C Programming Language", maybe a salute to its co-writer.

  • @FEARbraveheart
    @FEARbraveheart 8 лет назад +1

    This is in my opinion the most compelling reason to script in bash or sh. I love the simplicity of which I can test each element individually.

  • @Z4KJ0N3S
    @Z4KJ0N3S 6 лет назад +1

    I'd love to take a class from this guy. What a collection of history!

  • @alsifjlasieflooo
    @alsifjlasieflooo 8 лет назад +2

    Wow, thank you so much! I've always wondered how these "pipelines" work but I couldn't find a consise explanation video.
    Now I just need to find another video, which goes deep into the specifics of 3D pipelines, because I can't find such a thing either...

  • @TzuriKatoa
    @TzuriKatoa 8 лет назад

    more of this delightful man, please.

  • @hrnekbezucha
    @hrnekbezucha 8 лет назад +10

    Unix is just bloody genious.

  • @goyabee3200
    @goyabee3200 8 лет назад +13

    Funny how they misinterpreted his mention of using grep, wc, and sort. He meant those are programs that you would frequently pipe data into, not that you would ever use them in a three-stage pipe as was shown in the animation, as that would make no sense at all, wc only outputs a count of lines, words or characters, none of which would make any sense to pipe into sort.

    • @aknagi
      @aknagi 8 лет назад +7

      +John Euell
      How big are the files that have 'fish' in:
      grep fish **/* -l | xargs wc | sort -r
      Near enough? :)

    • @migtrewornan8085
      @migtrewornan8085 8 лет назад

      +goyabee I only came down to read the comments because I didn't understand why anyone would sort the output of wc. I thought I must be wrong because I couldn't believe I knew better than Brian Kernighan. Thanks for explaining it wasn't his error that I spotted (I should have listened more closely to what he said instead of watching the animation).

    • @afroninjadeluxe
      @afroninjadeluxe 7 лет назад

      i put it in to terminal and it didnt work. not a great first experience.

  • @antopim
    @antopim 6 лет назад +1

    Thanks a lot for the lesson! i'll love more stuff unix related.

  • @CelmorSmith
    @CelmorSmith 8 лет назад

    Please more of these principles of how operating systems work today, had to learn this piping myself.

  • @chickenmonger123
    @chickenmonger123 8 лет назад

    Fascinating. I am getting a picture of how the systems work, and relates to me. That is to say what runs the machines and systems I use in my day to day life.

  • @andljoy
    @andljoy 8 лет назад +4

    Do one thing and do it well.
    Write Programs that work together
    Write programs to handle text streams, because that is a universal interface

  • @avro549B
    @avro549B 8 лет назад +1

    One of the living deities of the field, describing one of the fundamental ideas. Anything Kernighan's said or written is worth studying. If he published "Proctology for Amateurs" I'd pick it up without bothering to read the blurb.

  • @njclondon2009
    @njclondon2009 8 лет назад

    wow. a true legend. well done computerphile.

  • @RandomNUser
    @RandomNUser 8 лет назад +5

    This video has the perfect timing. I've got an exam on linux commands on the near future, pipelines included. Understanding the basics and the origins makes it so much easier.
    Thanks Computerphile!

    • @hellterminator
      @hellterminator 8 лет назад +1

      Really? I mean, how shitty do your teachers have to be to not get the idea o pipelines across?

    • @hellterminator
      @hellterminator 8 лет назад

      ***** I know but pipelines? That's something so trivial that when you know it exist you pretty much know everything there is to know (unless you want to know how they're implemented in the OS of course). It's hard to imagine someone knowing pipelines exist but not knowing how to use them unless they received their explanation from a blabbering idiot who couldn't put a decent sentence together.
      What I'm trying to say is that in this instance, the level of fail is so high that it's very hard to believe it could be the student's fault alone.

    • @AndyWJP
      @AndyWJP 8 лет назад

      +hellterminator I agree. How much effort does it take to go to a command line and play around with the commands to solidify your understanding of these basics?

  • @realraven2000
    @realraven2000 8 лет назад +4

    3:12 also it saves time especially with multithreaded systems as you do multiple processing at the same time while reading in the first input rather than doing everything sequential. Process1+2+3 run on the data at the same time, so ideally you can save 2/3 of the processing time with proper multithreading.

    • @majorgnu
      @majorgnu 8 лет назад +8

      +Realraven2000 In most real-world scenarios where a pipe takes any significant amount of time, a single process is *the* bottleneck and takes orders of magnitude more time than the others, so you end up not making much use of the multiple cores or processors.
      Try to find mutithreaded versions of the bottleneck program, like pigz instead of gzip, or use something like GNU parallel to run multiple iterations of the same job at a time.

    • @IsaacLevy
      @IsaacLevy 8 лет назад +1

      +Major Gnuisance also piping to sort, the example in the video is a bit clunky since this requires buffering the entire input. But pipes are especially useful when one of the steps is slow, because the OS will handle scheduling and the speedy parts will block (i.e. pause) until the slow parts clear the buffer.

  • @sharadchandakacherla8268
    @sharadchandakacherla8268 7 лет назад

    man! it must be a privilege to talk to this man.

  • @Vhite
    @Vhite 8 лет назад +1

    Hey, I'm currently learning some UNIX basics for school, thanks for motivation (and procrastination).

    • @nerd2544
      @nerd2544 Год назад

      howz it going
      mf is watching vtubers now i see 😼😼😼

  • @paulcassidy4559
    @paulcassidy4559 8 лет назад +1

    I'm only a few seconds in, but damn, he explains things so, so well!

  • @saedabdrabu9390
    @saedabdrabu9390 2 года назад

    thank you so much. you explained it way easier than the book im studying from.

  • @pweddy1
    @pweddy1 4 года назад +2

    Perhaps the most important thing he says here is:
    "Having small programs is better than big programs."
    I was using all the Unix utils when I was in college and when I graduated from college in my first job out of school 30 years ago and when I look at Linux today I think they forgot that "Small programs are better than big programs."
    The version of Awk in Debian today is orders of magnitude more complex than the version I was using 20 years ago. And that starts to defeat the purpose.
    I think this is perhaps one if the biggest flaws of "batteries include" programming languages of today. They try so hard to do everything, that they forgot to "just do one thing well."

  • @therealEmpyre
    @therealEmpyre 8 лет назад +9

    I remember using this feature in DOS, but of course, UNIX did it before there was DOS.

    • @cigmorfil4101
      @cigmorfil4101 6 лет назад +7

      therealEmpyre also the DOS version of the pipe worked in exactly the method he says the Unix pipe avoids: it wrote the output of the first program into a temporary file and did this until the first program finished running, then it connected this temporary file to stdin of the second program and if that piped its output into program 3 the output would be connected to another temporary file and program 2 runs to completion before deleting its temporary stdin file and connecting its temporary stdout file to stdin of program 3, etc.

  • @gjermundification
    @gjermundification Месяц назад

    Is there a correlation between pipe and unix domain socket?

  • @TTaylor
    @TTaylor 8 лет назад +7

    "Why is it better to use numerous small programs rather than one massive program"?
    "Because, for one thing, using small programs is better than using one big program..."
    Ok, to be fair, he did answer the question later in the video.

  • @casperes0912
    @casperes0912 6 лет назад

    This is my favourite part of Unix systems. Alongside > and >>.

  • @akirubamiru6700
    @akirubamiru6700 4 года назад

    So I was doing pipeline in bash without even knowing what I was doing, but now I grasp more easily compared to the first time when I watch the video.

  • @kahrkunne3960
    @kahrkunne3960 8 лет назад

    Pipes are one of the most useful things in computer which I use on a day-to-day basis. Pretty much not a day goes by without me using them in some way or another.

  • @kurosenchou
    @kurosenchou 8 лет назад

    I believe this was filmed at the same event as his previous video. The background is the same, literally

  • @PrimusProductions
    @PrimusProductions 8 лет назад +1

    Does this assume each program has one and only one input and one and only one output?
    If so how does this relate to nesting single parameter functions/methods inside each other?
    e.g.
    double square (double x) {
    return x^2;
    }
    double cube (double x) {
    return x^3;
    }
    And elsewhere you put
    System.out.print(cube(square(2)));
    and it outputs 64

    • @simon24h
      @simon24h 8 лет назад

      +Primus Productions You should try your program before you say what it produces. It should output 64.

  • @jjmontesl
    @jjmontesl 8 лет назад +5

    The lesser-known "pv" command deserved to be mentioned somewhere in this thread...

    • @nobytes2
      @nobytes2 4 года назад +1

      Pipe viewer is not a standard package, but it is awesome for sure!

  • @ashishrao3069
    @ashishrao3069 4 года назад +1

    Please someone make time travel possible so that I can witness these legends creating UNIX

  • @MrXperx
    @MrXperx 8 лет назад

    I learnt C from the K&R book :) Also pipes are extremely useful.

  • @ytdlam
    @ytdlam 8 лет назад

    is it possible to "pipe" to several instances of stdout at the same time and have different programs configured to receive those outputs?

  • @notlocalhorst
    @notlocalhorst 8 лет назад

    can't live without it (queue scorpions music) ... the concept is just awesome ... (well, ran into some buffer issues, but anyway)

  • @TheApatheticGuy
    @TheApatheticGuy 8 лет назад +19

    "wc | sort"
    wat

  • @resonance2001
    @resonance2001 8 лет назад +2

    Oh, I remember pipelines from my Amiga days...

  • @pev_
    @pev_ 2 года назад

    But there are programs like sorting (of any kind) that in themselves can still be small, but that need the whole output of the previous program before they can really sort it, so there you really need a lot of memory if you have a large catalog of things that need sorting. Then the only advantage of the pipeline mechanism is the simple syntax, not any resource saving.

  • @RedsBoneStuff
    @RedsBoneStuff 7 лет назад

    My teacher actually recommended this video. Well done.

  • @FeralPhilosopher
    @FeralPhilosopher 8 лет назад

    pipelines are so nice. Life is much easier with them than without them! :D

  • @shzshirsh
    @shzshirsh 8 лет назад

    I wonder. If the output of 1 command were too big to store in a file, where is it stored temporarily, until it is passed to another command as input?

    • @OleTange
      @OleTange 8 лет назад +1

      +Shirsh Zibbu The pipe is not stored to a temporary file. What is normally happening in 'prg_a | prg_b' is that prg_a generates some output. When prg_a has generated a full block (typically 4 KB) this block is passed to prg_b, which reads the block. If prg_b is not ready to read the block yet, prg_a will be blocked and not run until prg_b has read the block. Likewise prg_b can be waiting for a new block from prg_a and in that situation prg_b will be blocked and not use any CPU-time.

  • @kurosenchou
    @kurosenchou 8 лет назад

    HE IS LEGEND!!!

  • @casperghst42
    @casperghst42 9 месяцев назад

    I remember being taught this subject at school, not the easiest thing to understand .... this was back in the early 90s.

  • @ArumesYT
    @ArumesYT 7 лет назад

    What happens when program 1 can output data faster than program 2 can process it? Does the data get buffered in RAM (which is what happens in another OS's pipeline that I know of), or does program 1 halt at the output command until program 2 asks for more data? If the data gets buffered, I don't really see the benefit in terms of required storage space mentioned at 2:22. RAM has always been more expensive than storage, so if the cost/availability of storage space is a limiting factor, the cost/availability of RAM is even worse.

    • @maowtm
      @maowtm 7 лет назад

      Program 1 will be blocked until program 2 used up the data, but in some case there's also a small buffer.

    • @javabeanz8549
      @javabeanz8549 6 лет назад

      you also have to remember the TIME COST, and when this was first created, you wanted to use as little time on the system as possible, as there was a line waiting. You can also consider the fact that RAM is accessed much more quickly than a drive, unless you happen to be working with something like Intel's OPTANE products.

  • @Physhi
    @Physhi 8 лет назад +1

    I tried explaining the importance of the shell to someone and even broke it down to a sandwich assembly line or what have you. I just had these confused eyes looking at me.
    Why can't I share important scientific (though computerized) breakthroughs with anyone!? It's not fair!
    Signed -- a GNU user.

  • @joelproko
    @joelproko 8 лет назад +6

    A better animation would have been to have water flowing through the pipes and change color each time it went through a new little program. Ideally enough water for some of it to still be going into program 1 while some of it is already coming out of program 2.

    • @majorgnu
      @majorgnu 8 лет назад +12

      +joelproko Colored dots would be more appropriate, I think. But you're right, the animation fails to convey the important point that, conceptually, all programs in the pipeline will be running concurrently.
      Otherwise, the system would necessarily have to hold the full output of each program in the pipeline before starting the next one, which would return us to the problem of having to store those intermediate results somewhere.

    • @TaiFerret
      @TaiFerret 8 лет назад

      +Major Gnuisance I think MS-DOS used to run the programs one at a time and store the intermediate results in temporary files.

    • @okaro6595
      @okaro6595 8 лет назад

      +TaiFerret MSDOS 1.0 was based on CP/M. MSDOS 2.0 copied many features from Unix (path names, redirection, pipes, asciiz strings) but as there was no multitasking the pipes are really pseudo pipes that use temporary files. In practice they can do most of the stuff that Unix command pipes. There are exceptions, for example the first program cannot be interactive as prompts would be written just to the file and never seen. Also in MS DOS programs of the bypassed the OS in IO so they would not be affected by redirection or pipes.
      In Unix the pipe is an integral part of the actual OS. In MSDOS it is just a command line element. Windos 8.1 works like MSDOS. One can test this with dir /s /b | find "\" at the root. With real pipes the output would start immediately. Windows has real pipes also but they are separate from the standard IO-system.

    • @majorgnu
      @majorgnu 8 лет назад +3

      TaiFerret As ***** explained, MS-DOS pipes are naught but a bastardization of the pipes of Unixlike OSes.
      Let's not bring the dabblings of such a lowly OS family into the conversation.

    • @dipi71
      @dipi71 8 лет назад +1

      This reminds me of Douglas Crockford who says that JavaScript is the single computer language with most installations on earth because virtually every web browser on any OS on any computer, mobile device etc implements it. There are other instances where ubiquity doesn't correlate with usability, e.g. machine code or non-coding DNA.
      Also, I would dial your »million instances« to maybe a dozen, because Unix is a tad older than DOS, and every larger network with some servers it has components running shells with redirection capabilities in some form or other. Think of all those routers, switches, firewalls and other appliances with built-in busybox or proper Unix/Linux installation.
      Additionally, for the recent ten years, iOS and Android mobile devices have become so numerous, each single one of them with FreeBSD or Linux on board, each of them (including watchOS) with a fully functioning bash. In my mind, the Unix way easily is the predominant way of accessing digital technology. It has even been standardized (POSIX), which cannot be said about GUIs (tiles or ribbons, anybody?).
      Conversely, Microsoft was forced by the market to put some semblence of POSIX conformity into WinNT and make the DOS shell more capable. But it's still a nightmare of incompatibilities to automate something with it. My latest example with the DOS idiocy: try to put an ISO-8601-style date+time stamp into the name of a file to be written into. Yeah.

  • @kslavvko
    @kslavvko 3 года назад

    I just use pipes every day :) wonderful concept

  • @kurokamei
    @kurokamei 5 лет назад

    So grep is monad?

  • @BEP0
    @BEP0 8 лет назад +1

    Nice.

  • @timothygalvin3021
    @timothygalvin3021 8 лет назад +4

    This is interesting but I was very distracted by the weirdly completely empty book shelves.

  • @JBLewis
    @JBLewis 7 лет назад +1

    Professor Kernighan *almost* touches on PowerShell in the video

  • @AshleyMorganAnderson
    @AshleyMorganAnderson 8 лет назад

    Wait, who's piping the output of wc in to sort? It's output (when it's input is from a pipe and not command line arguments) is just three numbers on one line :-/

  • @cuttlefishn.w.2705
    @cuttlefishn.w.2705 4 года назад

    Who sorts the output of wc?

    • @pev_
      @pev_ 2 года назад

      Indeed, that flashed in my mind also, if I remember correctly wc is word count, so it just outputs a number.

  • @ajgelado
    @ajgelado 5 лет назад

    MS-DOS has had Unix-style input/output redirection in its shell since version 1.0 (1981) - that's four years before the first version of "GUI" Windows (Windows 1.0, 1985), and 12 years before the first version of Windows as an OS (Windows NT 3.1, 1993). Thus, redirection wasn't "retrofitted" into Windows - it was built-in from the start. MS-DOS and Windows is more Unix-like than most people realize (which is reasonable, since Microsoft was a vendor of Unix back in the 80s - they made and sold Xenix for the IBM PC).

    • @eugrus
      @eugrus 4 месяца назад

      That's input/output redirection to/from files you are referring to. MS-DOS did not support anonymous pipes which Brian Kerninghan explained in the video. That's, you could not make a one-liner to use output of one program as input for another (|). There was a workaround to reroute the output (>) into a tmp file and then use this file for input in a separate line (

  • @InnoVintage
    @InnoVintage 4 года назад

    Pipeline is one of the most powerful uses of the properties of operating systems and it is just one tiny thing

  • @VoxAcies
    @VoxAcies 8 лет назад

    This video really could do with some examples. Unix pipes are very easy to demonstrate and you can appreciate results almost instantly.
    I think the people who don't already understand what pipes are, will not understand from this video the importance of the subject. Not only pipes are absolutely necessary to efficiently use shell, but they also embody one of the core Unix principles: building complex functional systems from simple and easy to use blocks. I could go on for quite some time about pipes, so I'll stop here.
    Just to put things into perspective, I checked my shell history on several Unix machines, and on average about 15 to 20% of my commands contain pipes.

  • @simonrose2
    @simonrose2 8 лет назад +16

    Isn't this guy the "K" in awk?

    • @DavidChipman
      @DavidChipman 7 лет назад +1

      Yep! It sure is!

    • @FandCCD
      @FandCCD 5 лет назад +6

      And the K in K&R

    • @charlesarmstrelli1688
      @charlesarmstrelli1688 4 года назад

      @@FandCCD not in this one, the k stands for Ken thompson!

    • @miyalys
      @miyalys 4 года назад +3

      @@charlesarmstrelli1688 No, it's short for Kernighan & Ritchie, the authors of the book The C Programming Language.

  • @AlexeyZlobin
    @AlexeyZlobin 5 лет назад +2

    The greatest idea in language design. Too bad so few modern programming languages has it.

  • @CaptainParalytic
    @CaptainParalytic 8 лет назад

    If only MVS/CMS Pipelines was part of Unix, what a wonderful world it would be.

  • @PestOnYT
    @PestOnYT 7 лет назад

    Nice explanation. However, piping the output of "wc" into sort .... well ... one line. The other way around is more common. Still nicely done.

  • @rooneye
    @rooneye 3 года назад +1

    I used this today to pipe the output of neofetch through to lolcat to make the text a rainbow of colours! ">_ neofetch | lolcat" 😁

  • @farischugthai5598
    @farischugthai5598 7 лет назад +1

    "big word for store it" hahahahahahaha

  • @lcdvasrm
    @lcdvasrm 6 лет назад

    but ? users should be able to tune the 'wait time' and/or 'chunk bytes count' aspects of this ? no ?

  • @davidgillies620
    @davidgillies620 7 лет назад +1

    And when you combine pipes with xargs, amazing things happen

  • @PhilippeCarphin
    @PhilippeCarphin 6 лет назад

    Sorting the output of wc lol! Cause he gave the examples in that order.

  • @DavidLindes
    @DavidLindes 2 года назад

    It's a minor pity that you took his mention (at 3:46 and 4:35) of "grep, wc, and sort" as the basis for the animation... piping the output of wc into sort is... a bit pointless. Now if wc was replaced by awk (3:51), that'd make a lot more sense. :) Ah well! Still, a cool video on a very very very useful paradigm.

  • @oscarwang7920
    @oscarwang7920 3 года назад

    Do one thing , do it well . I love Unix

  • @ctraver
    @ctraver 8 лет назад

    I don't use pipes often- I mostly use my computer like a typical consumer, and the aren't many use cases for them in this context. When I do use them , though, every alternative would be a giant pain in the ass. Whether it's a more complicated swiss army knife tool I'd need to learn, messing with files, or coding up a custom solution, it would just be a giant pain.

  • @smallmoneysalvia
    @smallmoneysalvia 5 лет назад +2

    grep | wc | sort?
    Sounds like one awk.

  • @MizoxNG
    @MizoxNG 8 лет назад

    so this is kinda like APIs yes?

  • @subh1
    @subh1 8 лет назад

    ok, I guess I don't get the complexity in this. An output of one program is being fed as input to another program. I mean what's the big deal about coming up with the command-line "|" (pipe) symbol that would be interpreted to do that? Why would it even require discussion among multiple people and be such an historic thing to be implemented? Isn't it just a trivial and obvious thing to do when writing a parser? What the non-obvious / non-trivial part about it?

    • @A1Skeptic
      @A1Skeptic 8 лет назад +2

      +subh1 The non-obvious at the time idea of pipes had to be thought of by someone comfortable with poking around in the Unix kernel , then the code to make pipes work had to be invented and integrated into the operating system. I guess inventing code that hadn't previously existed just isn't that impressive to you.

  • @johnkapri6306
    @johnkapri6306 8 лет назад

    "cat random_binary_file.dat | hd" I love this to death. So usefull!

    • @bytefu
      @bytefu 8 лет назад

      +John Kapri It looks like "hd < random_binary_file.dat" will work too.

    • @johnkapri6306
      @johnkapri6306 8 лет назад

      +John Kapri I just realised I made an alias in my .bashrc for that to work. Full command is "cat random_binary_file.dat | hexdump -C". Shows you a nice hexdump including an ASCII readout of whatever file you pipe in. "hexdump -C file.dat" would work as well, but you know... PIPES!!!

  • @daanwilmer
    @daanwilmer 8 лет назад +1

    Suppose you downloaded all computerphile videos in a single folder, and you want to list all files containing unix:
    ls -l | grep "unix"
    ls -l lists all files in the folder, with each filename per line.
    grep "unix" retains all lines containing "unix"
    And voila: you have all filenames which contain "unix" :)

    • @daanwilmer
      @daanwilmer 8 лет назад +2

      Also, if you just want to know how many files there are containing "unix" in the filename, just throw in "wc -l" to count lines:
      ls -l | grep "unix" | wc -l

    • @majorgnu
      @majorgnu 8 лет назад +1

      +Daan Wilmer
      And then there were a bunch of files with newlines in their names and your count went over. Tsk, tsk.
      find -iname '*unix*' -type f -printf 1 | wc -c
      The 1 is arbitrary, any single-byte character would do.

    • @joelproko
      @joelproko 8 лет назад +2

      +Daan Wilmer Or just
      ls -l | grep -c "unix"
      And to make sure it doesn't care about capitalization:
      ls -l | grep -c -i "unix"

    • @bjornmu
      @bjornmu 8 лет назад

      +Daan Wilmer But this you can achieve without pipes: ls -ld '*unix*'.

    • @gordoofdoom
      @gordoofdoom 8 лет назад

      +Bjorn P. Munch you missed the -i for ignore case in the grep command. I don't think that ls -ld ignores the case. It certainly doesn't on the linux system I use every day.

  • @proxxyBean
    @proxxyBean 8 лет назад

    My .bashrc depends heavily on pipes.

  • @makenova
    @makenova 8 лет назад

    This made me think of lazy evaluation. Please cover lazy evaluation!

  • @clairecavanaugh5861
    @clairecavanaugh5861 8 лет назад

    I wish that Brian Kernighan was my grandpa.

  • @hz8711
    @hz8711 Месяц назад

    how to make a linux/unix pro mad in one command:
    cat something | grep something

  • @andrewgc19881
    @andrewgc19881 8 лет назад +1

    he needs more books.... for credibility

    • @douwehuysmans5959
      @douwehuysmans5959 6 лет назад +1

      andrew campbell He's the one that writes the books

  • @hikingpete
    @hikingpete 8 лет назад +1

    I got a laugh out of seeing wc in the middle of a pipeline there. grep, wc, and sort are all things you'd use in a pipeline, but you would never arrange them like that.

  • @ddostesting
    @ddostesting 8 лет назад +1

    IT makes no sense to pipe wc to sort. wc outputs 1 line, and there is no sense to sort that.

    • @javabeanz8549
      @javabeanz8549 6 лет назад +2

      it only outputs a single line if running against a single file...

  • @akramnemer1844
    @akramnemer1844 2 года назад

    reminds me of the laughing pain meme

  • @directorans
    @directorans 8 лет назад +1

    why would you pipe the output of wc into sort? XD

    • @OleTange
      @OleTange 8 лет назад

      +1classified1 Oh. I was not the only one being puzzled by that.

    • @javabeanz8549
      @javabeanz8549 6 лет назад +1

      Maybe you want to get a word count from a number of documents, then sort them by the word count.

  • @amihartz
    @amihartz 8 лет назад

    Pipes are incredibly useful but a lot of people also don't use here strings which bothers me. Here strings push a string into the STDIN of another command. A lot of people instead will just echo the string and pipe the result of the echo command into the command to process the string, but to me I've always found that to be ugly because you can just pass the string directly into it with here strings.

    • @andreroth9212
      @andreroth9212 8 лет назад

      agree, +1 for here strings. but echo is more efficient, as here strings usually create a file in tmp, in order to get an fd...

    • @vonkruel
      @vonkruel 8 лет назад

      +Amelia Hartman I don't think it really matters, and the here string may actually be slower (if that even matters which it probably doesn't). Personally I prefer to avoid writing to the filesystem, but just do it whichever way you prefer IMO.

  • @Andrewsarcus
    @Andrewsarcus 8 лет назад

    Is the pipeline the same as or similar to object orientated programming ?

    • @tuxino
      @tuxino 8 лет назад

      +Andrewsarcus Not really. It does tackle some of the concerns behind the idea of OOP, but in a completely different way.

    • @joelproko
      @joelproko 8 лет назад

      +Andrewsarcus Not really, it's more like functional programming.
      ls -l | grep -i "unix"
      would be something like
      grep(ls(LSOPT_LIST),"unix",GREPOPT_IGNORECASE)
      if grep and ls were PHP functions.

    • @d34d10ck
      @d34d10ck 8 лет назад

      +Andrewsarcus It's not the same, but pipelining doesn't have to be stringbased like it's the case with the UNIX shell. The windows powershell for example is object oriented and pipes .NET objects from program to program.

  • @maxwellplotkin4821
    @maxwellplotkin4821 8 лет назад +1

    "a mechanism for screwing..." ;-)

  • @AndersJackson
    @AndersJackson 6 лет назад

    Piping stuff like this is functional programmen.