Unix Pipeline (Brian Kernighan) - Computerphile

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
    @fdk70148 жыл бұрын

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

  • @rbrrhllngswrth

    @rbrrhllngswrth

    8 жыл бұрын

    That is a really excellent idea!

  • @TFCxAddict

    @TFCxAddict

    8 жыл бұрын

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

  • @darcy6698

    @darcy6698

    11 ай бұрын

    he does

  • @xeigen2
    @xeigen28 жыл бұрын

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

  • @axlslak

    @axlslak

    2 жыл бұрын

    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 ай бұрын

    @@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
    @trylleklovn8 жыл бұрын

    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 жыл бұрын

    +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 жыл бұрын

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

  • @trylleklovn

    @trylleklovn

    8 жыл бұрын

    +PropaneWP Haha :D

  • @THB192
    @THB1928 жыл бұрын

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

  • @markfrombriz

    @markfrombriz

    5 жыл бұрын

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

  • @compu85
    @compu858 жыл бұрын

    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.

  • @goyabee3200
    @goyabee32008 жыл бұрын

    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 жыл бұрын

    +John Euell You just made a lower level Skype

  • @imaginaoYouTubesoquecomarrobas

    @imaginaoYouTubesoquecomarrobas

    2 жыл бұрын

    That's honestly wild 😂

  • @deepumali7508

    @deepumali7508

    2 жыл бұрын

    Beautiful....

  • @MrJegerjeg

    @MrJegerjeg

    Ай бұрын

    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

  • @dice3000
    @dice30008 жыл бұрын

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

  • @LeiosLabs

    @LeiosLabs

    8 жыл бұрын

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

  • @shadowmil
    @shadowmil8 жыл бұрын

    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 жыл бұрын

    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 жыл бұрын

    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 output.out" be an extremely simple example of pipelining?

  • @BaseSixtyFour
    @BaseSixtyFour8 жыл бұрын

    a living legend

  • @DragoniteSpam
    @DragoniteSpam8 жыл бұрын

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

  • @Guillaurent
    @Guillaurent8 жыл бұрын

    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 жыл бұрын

    +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'

  • @ruthklein7838
    @ruthklein78384 жыл бұрын

    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
    @telesniper23 ай бұрын

    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?

  • @TheHoaxHotel
    @TheHoaxHotel8 жыл бұрын

    It's a Unix system, I know this!

  • @lucasb3h3m0th

    @lucasb3h3m0th

    5 жыл бұрын

    It's Computer Science .at higher level

  • @FEARbraveheart
    @FEARbraveheart8 жыл бұрын

    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.

  • @hemanthkumarHere
    @hemanthkumarHere8 жыл бұрын

    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
    @CaptainDangeax8 жыл бұрын

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

  • @goyabee3200
    @goyabee32008 жыл бұрын

    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 жыл бұрын

    +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.

  • @johnflano
    @johnflano8 жыл бұрын

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

  • @arthur_p_dent4282
    @arthur_p_dent4282 Жыл бұрын

    I could listen to Brian talk for hours.

  • @Z4KJ0N3S
    @Z4KJ0N3S5 жыл бұрын

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

  • @alsifjlasieflooo
    @alsifjlasieflooo8 жыл бұрын

    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
    @TzuriKatoa8 жыл бұрын

    more of this delightful man, please.

  • @avro549B
    @avro549B8 жыл бұрын

    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.

  • @sharadchandakacherla8268
    @sharadchandakacherla82687 жыл бұрын

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

  • @njclondon2009
    @njclondon20098 жыл бұрын

    wow. a true legend. well done computerphile.

  • @andljoy
    @andljoy8 жыл бұрын

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

  • @CelmorSmith
    @CelmorSmith8 жыл бұрын

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

  • @chickenmonger123
    @chickenmonger1238 жыл бұрын

    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.

  • @antopim
    @antopim6 жыл бұрын

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

  • @pweddy1
    @pweddy14 жыл бұрын

    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."

  • @RandomNUser
    @RandomNUser8 жыл бұрын

    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 жыл бұрын

    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
    @realraven20008 жыл бұрын

    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 жыл бұрын

    +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 жыл бұрын

    +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.

  • @TTaylor
    @TTaylor8 жыл бұрын

    "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.

  • @Vhite
    @Vhite8 жыл бұрын

    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
    @paulcassidy45598 жыл бұрын

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

  • @saedabdrabu9390
    @saedabdrabu93902 жыл бұрын

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

  • @therealEmpyre
    @therealEmpyre8 жыл бұрын

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

  • @cigmorfil4101

    @cigmorfil4101

    6 жыл бұрын

    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.

  • @ashishrao3069
    @ashishrao30694 жыл бұрын

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

  • @jjmontesl
    @jjmontesl8 жыл бұрын

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

  • @nobytes2

    @nobytes2

    4 жыл бұрын

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

  • @akirubamiru6700
    @akirubamiru67004 жыл бұрын

    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.

  • @casperes0912
    @casperes09126 жыл бұрын

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

  • @kurosenchou
    @kurosenchou8 жыл бұрын

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

  • @resonance2001
    @resonance20018 жыл бұрын

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

  • @kahrkunne3960
    @kahrkunne39608 жыл бұрын

    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.

  • @MrXperx
    @MrXperx8 жыл бұрын

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

  • @RedsBoneStuff
    @RedsBoneStuff7 жыл бұрын

    My teacher actually recommended this video. Well done.

  • @KenoxProductions

    @KenoxProductions

    7 жыл бұрын

    Same here.

  • @RedsBoneStuff

    @RedsBoneStuff

    7 жыл бұрын

    ***** Do you happen to live in Slovenia?

  • @KenoxProductions

    @KenoxProductions

    7 жыл бұрын

    Yes...

  • @RedsBoneStuff

    @RedsBoneStuff

    7 жыл бұрын

    Well, we better get working on the task then, it's till tomorrow evening ;)

  • @timothygalvin3021
    @timothygalvin30218 жыл бұрын

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

  • @gjermundification
    @gjermundificationАй бұрын

    Is there a correlation between pipe and unix domain socket?

  • @joelproko
    @joelproko8 жыл бұрын

    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 жыл бұрын

    +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 жыл бұрын

    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 жыл бұрын

    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.

  • @Physhi
    @Physhi8 жыл бұрын

    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.

  • @casperghst42
    @casperghst429 ай бұрын

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

  • @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.

  • @notlocalhorst
    @notlocalhorst8 жыл бұрын

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

  • @PrimusProductions
    @PrimusProductions8 жыл бұрын

    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.

  • @VoxAcies
    @VoxAcies8 жыл бұрын

    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.

  • @TheApatheticGuy
    @TheApatheticGuy8 жыл бұрын

    "wc | sort" wat

  • @JBLewis
    @JBLewis7 жыл бұрын

    Professor Kernighan *almost* touches on PowerShell in the video

  • @simonrose2
    @simonrose28 жыл бұрын

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

  • @DavidChipman

    @DavidChipman

    7 жыл бұрын

    Yep! It sure is!

  • @FandCCD

    @FandCCD

    5 жыл бұрын

    And the K in K&R

  • @charlesarmstrelli1688

    @charlesarmstrelli1688

    4 жыл бұрын

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

  • @miyalys

    @miyalys

    4 жыл бұрын

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

  • @ytdlam
    @ytdlam8 жыл бұрын

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

  • @AvailableUsernameTed

    @AvailableUsernameTed

    8 жыл бұрын

    +ytdlamPerhaps 'tee' is what you are looking for.

  • @AvailableUsernameTed

    @AvailableUsernameTed

    8 жыл бұрын

    echo 123 | tee >(tr 1 a) | tr 1 b works (from Stackoverflow)

  • @ArumesYT
    @ArumesYT7 жыл бұрын

    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.

  • @FeralPhilosopher
    @FeralPhilosopher8 жыл бұрын

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

  • @ajgelado
    @ajgelado5 жыл бұрын

    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 (

  • @AlexeyZlobin
    @AlexeyZlobin5 жыл бұрын

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

  • @AshleyMorganAnderson
    @AshleyMorganAnderson8 жыл бұрын

    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 :-/

  • @shzshirsh
    @shzshirsh8 жыл бұрын

    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 жыл бұрын

    +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
    @kurosenchou8 жыл бұрын

    HE IS LEGEND!!!

  • @kslavvko
    @kslavvko3 жыл бұрын

    I just use pipes every day :) wonderful concept

  • @BEP0
    @BEP08 жыл бұрын

    Nice.

  • @rooneye
    @rooneye3 жыл бұрын

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

  • @farischugthai5598
    @farischugthai55987 жыл бұрын

    "big word for store it" hahahahahahaha

  • @davidgillies620
    @davidgillies6207 жыл бұрын

    And when you combine pipes with xargs, amazing things happen

  • @InnoVintage
    @InnoVintage4 жыл бұрын

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

  • @kurokamei
    @kurokamei5 жыл бұрын

    So grep is monad?

  • @DavidLindes
    @DavidLindes2 жыл бұрын

    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.

  • @PestOnYT
    @PestOnYT7 жыл бұрын

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

  • @lcdvasrm
    @lcdvasrm5 жыл бұрын

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

  • @cuttlefishn.w.2705
    @cuttlefishn.w.27054 жыл бұрын

    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.

  • @ctraver
    @ctraver8 жыл бұрын

    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.

  • @daanwilmer
    @daanwilmer8 жыл бұрын

    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 жыл бұрын

    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 жыл бұрын

    +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 жыл бұрын

    +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.

  • @CaptainParalytic
    @CaptainParalytic8 жыл бұрын

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

  • @oscarwang7920
    @oscarwang79203 жыл бұрын

    Do one thing , do it well . I love Unix

  • @subh1
    @subh18 жыл бұрын

    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 жыл бұрын

    +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.

  • @PhilippeCarphin
    @PhilippeCarphin5 жыл бұрын

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

  • @smallmoneysalvia
    @smallmoneysalvia5 жыл бұрын

    grep | wc | sort? Sounds like one awk.

  • @MizoxNG
    @MizoxNG8 жыл бұрын

    so this is kinda like APIs yes?

  • @hz8711
    @hz8711Ай бұрын

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

  • @directorans
    @directorans8 жыл бұрын

    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 жыл бұрын

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

  • @johnkapri6306
    @johnkapri63068 жыл бұрын

    "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!!!

  • @hikingpete
    @hikingpete8 жыл бұрын

    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.

  • @clairecavanaugh5861
    @clairecavanaugh58618 жыл бұрын

    I wish that Brian Kernighan was my grandpa.

  • @andrewgc19881
    @andrewgc198818 жыл бұрын

    he needs more books.... for credibility

  • @douwehuysmans5959

    @douwehuysmans5959

    6 жыл бұрын

    andrew campbell He's the one that writes the books

  • @RisinT96
    @RisinT968 жыл бұрын

    Computer guys really like the term "pipeline", Unix Pipeline, CPU Pipelining and etc...

  • @Shifticek

    @Shifticek

    8 жыл бұрын

    +Tal Risin pipeline pipeline is the best

  • @0pyrophosphate0

    @0pyrophosphate0

    8 жыл бұрын

    +Tal Risin It's not just about liking the word, it actually means the same thing in all cases, whether it's a UNIX pipeline, CPU pipeline, or graphics pipeline. They're all fundamentally the same thing.

  • @RisinT96

    @RisinT96

    8 жыл бұрын

    0pyrophosphate0 A cpu piepline is quite different from a UNIX pieplenie...

  • @0pyrophosphate0

    @0pyrophosphate0

    8 жыл бұрын

    Imagine a UNIX pipeline that said "fetch | decode | execute | write". UNIX operates on text strings and instruction pipelines operate on instructions, but the idea is the same.

  • @RisinT96

    @RisinT96

    8 жыл бұрын

    0pyrophosphate0 We are talking about different types of pipeline, I'm talking about the hardware level pipeline, the one that allows a pipelined multi-cycle cpu to begin doing the next instruction using the unused hardware *_before_* finishing the operation preceding it, unlike what you're talking about which is giving the output of one command *_after_* it finishes to the input of the next command. It's done using a series of registers inbetween the common 5 steps most instructions go through: IF/ID/EX/MEM/WB. This applies to other hardware systems and logic circuits, increasing throughput at the cost of latency. The ideas maybe similar in terms of the fact they they allow you to divide the operation into a batch of smaller and simpler operations, except that a cpu pipeline actually makes the process even more complicated and has a very different target which is increase of throughput, rather than simplification.

  • @fe12rrps
    @fe12rrps6 жыл бұрын

    Is the teddy bear drinking coffee or tea?

  • @makenova
    @makenova8 жыл бұрын

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

  • @akramnemer1844
    @akramnemer18442 жыл бұрын

    reminds me of the laughing pain meme

  • @proxxyBean
    @proxxyBean8 жыл бұрын

    My .bashrc depends heavily on pipes.

  • @ddostesting
    @ddostesting8 жыл бұрын

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

  • @javabeanz8549

    @javabeanz8549

    6 жыл бұрын

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

  • @apenasmeucanal5984
    @apenasmeucanal59848 жыл бұрын

    Hello world

  • @amihartz
    @amihartz8 жыл бұрын

    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.