"Everything is a file" in UNIX

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey what's going on y'all this is Stevie with another episode of project twine and today we're going over a common phrase that you'll hear when working with UNIX etype systems and that is everything is a file so we're gonna go a little bit into what this means and give you a couple examples of it and play as well as trying to understand the rationale behind the phrase so what's the rationale behind using everything as a file well if you think about it everything on your computer is really just a stream of bytes or a bunch of characters just put together that represent a bunch of different things so if we have everything represented as a file that means we have a one protocol just one protocol and so if we understand how this one thing works we understand how a lot of different things work so this allows us for better interoperability so we can use a bunch of different tools together with the file format and we can reuse tools and make them communicate with each other and so we're really allowing ourselves for a much better form of modularity the most important thing in my opinion and you'll see this in just a couple of seconds is that by using this simple text file format we have a really good sense of transparency when we're working on a Linux system or UNIX system you'll start to see that pretty much everything really everything is represented as a file but all of these things that I just mentioned so modularity like interoperability like transparency these are all part of a bigger picture so the original developers and the original kind of founders of the UNIX operating system came up with a set of approaches a kind of mindset that you bring when you're building software technology and throughout your engineering career you will start to see how deep of an impact this sort of mindset has had and how its leaked into pretty much oh like everything that we do as engineers so we can just think of the practice of having the text file represent a lot of different things as being one of the core principles derived from this UNIX philosophy I found a really good quote from the book the pragmatic programmer and the author mentions the idea of combining small sharp tools and the use of one common underlying format and that is the blind oriented plain text file to accomplish much larger and complex tasks and we'll see this in just a couple seconds alright so I'm logged in onto a plain Santa Wes server here and I'm just gonna run through a couple quick examples that demonstrate that everything in UNIX is really just a file so let's start off with the very basics so let's go ahead and just create a file called basic text file dot txt I'm just gonna write hello there and then I'm just gonna quit out of it and let's go ahead and also make a directory and then I'm just going to list out what we just made in a detailed format so in the first column you can see that basic text file has a dash right and the one below that has a D so what's going on here well basic text file the dash represents that basic text file it is just a regular file and the D represents that the directory that we just made is also a file but a special type of file called a directory so what I'm trying to show here is that the things that we kind of take for granted like a directory it's just a file it just takes a different type of perspective to see that our directory is also just a file but it functions slightly different than the regular text file does alright so you'll start to see that everything in UNIX is just a file now all right well let's go ahead and explore some other things whoa this Ellis thing that I've been using is that a file well if I going to /bin and I use LS and I look for Ellis interestingly enough it's right there and I just do LS dash L and just like let's only look for the things that are start with our and with that LS and you'll see that this is also just a regular type of file hmm so that must mean that executables are the things that we use to run our system are just files as well that's really interesting so this goes even much much deeper and so what if I try something like going into this directory that I made and then let's run then in the background so this ampersand you don't really have to care about it for now but the ampersand means let's run it in the background I'm going to run it in the background and it gives us a number seven thousand one hundred twenty seven what does that mean basically UNIX is assigning it a number so if I go into /proc right and I list things inside there and I look for that seven thousand one hundred twenty seven number it's there for some reason and it just came out because I ran that process so what does that mean well that means that the processes are even represented as files in this case these files are directories so if I let's look for that seven thousand one hundred twenty seven thing there it is addy so its directory interesting so what happens if I go into that directory and I LS the things inside well you'll start to see that all the attributes of that file are actually listed right here what about things like like where we ran that file as a matter of fact if you might remember we ran it from that directory that we made at the beginning which was like the tilde and then directory right so if I want to find out where a process is actually running from all I need to do is look within my own filesystem crazy right so if I just do LS dash L on CWD which stands for a current working directory I see that it's right there so is it this is a symbolic link it's a different type of file but nevertheless it's a file and it's telling us that we ran then from that directory called / root / directory which would be accurate and that if we do LS dash L on exe as a matter of fact we start to see that this even tells us where vim is located which is really crazy and this is also symbolic link but it's basically here to demonstrate that everything that has to do with our system can is shown in our system and edges as files and we just have to look within our file system to really recognize what's going on inside our computer so I just showed you how processes are really inherently transparent because when you create a process there's a corresponding directory or a type of file that's made in /proc that you can just look into and discover more about so this is kind of that UNIX way that UNIX philosophy of being very transparent about your software because we can just go into our file system to learn more about what's going on within our computer so I'm going to take this one step further and show you a concept show you that concept of interoperability which is the idea of being able to use different tools together and this is only possible because everything is just a file so let's go into slash tab here I'm just gonna list everything out so on the right hand side I just want to point this out that xvd a1 and xvd a are actually representative of my hard drive interesting so if i just LS dash l x.v da you see that this is also just a type of file but it's a special type of file it's called a block device file if you are paying close attention you might have also noticed that there's files called standard error standard and standard owl and if you've programmed before you would know that these are really important things in terms of being able to work with input and output and as a matter of fact if I just use one tool that you might have known echo which just basically echoes things back out for us if I echo that in to standard in we actually get that right back out which would not be the case if I put it out and something else right so basically what I'm showing here is that I'm using these two different things these two different types of files that are being kind of created spontaneously and being able to use them together now this is just scratching the surface of the type of things that you can do with the text files because everything is represented as a file as a matter of fact if I wanted to for example create a file to print right so if I go print file dot txt and go hello I want to print this right interestingly enough if I wanted to print this all I really need to do is do you know I could just cat print file dot txt and then pipe that into LP - B and then put it in my printer name here so this is crazy this is a simple command I'm just like putting together and because everything is represented as a file so even my printer I can just you know spontaneously print things off my command line and so this kind of sums up and I hope this has shown you as a demonstration of how everything is really just a file and because everything is just a file in that UNIX see sort of philosophy and in a unique see sort of way we're allowed word it's only empowered to do all these things by combining these little tools and because they're so modular and also because they're files it's so transparent we can learn so much about our systems just by exploring through our computer so I highly suggest you do the same and you just like go through your computer and you just look on you know on the different types of files that you have and you'll start to see that really that that phrase is true everything is a file well to be more specific everything is represented as a file no I hope that was helpful my throat is dead because this is my 95th recording so I hope that was helpful [Music]
Info
Channel: Stevie Jay
Views: 23,209
Rating: 4.9733586 out of 5
Keywords: programming, coding, javascript, computer science, software engineering, software, functional programming, system administration, nodejs, reactjs, service workers, chrome, system adminstration, unix, red hat, centos, servers, ansible
Id: dDwXnB6XeiA
Channel Id: undefined
Length: 11min 14sec (674 seconds)
Published: Sat Apr 08 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.