Beginner's Guide to the Bash Terminal

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
greetings and salutations and thank you for clicking on the video today it's the beginner's guide to the Bosch terminal this is the scariest part of Linux for new users you don't need to use a terminal to use Linux many distributions provide very nice GUI desktops graphic user interfaces that give you all of the point-and-click comfort that you're used to however in Linux bash is a big part of the system and if you ever run into a situation where you need help with a problem chances are if you are working with somebody in a forum or somebody's helping you directly they're going to tell you to open up a terminal so that they can help you to fix the problem also the terminal is very powerful and once you learn your way around you might find that you like working in a terminal better than doing the point-and-click thing because it allows you to do very complicated things with just a few little commands so in today's video I'm going to give you the crash course this is the beginners guide we're going to go through a whole bunch of information very quickly and the idea here is to provide one video that will help people who want to get started with mesh there are a lot of great tutorials on YouTube about bash most of them are multi-part series and they're very long and they go into a great deal of detail I myself posted one of those a little more than a year ago however this video is a crash course if you sit down and you watch this video from beginning to end you're going to have the very basic concepts and tools you need to actually use the terminal and most of what I'm going to show you is where to get more information so it's pretty cool now you can see why the terminal would be intimidating when you open one up all you get is a blinking cursor it doesn't tell you anything well that's the difference between bash and a GUI a GUI interface is one that will give you options you can pretty much intuitively figure out what you're going to do in the terminal when you're working at a command line it is assumed that you know what you want and so therefore it doesn't offer a great deal of help as you roll along Bosch assumes that you know what you're doing so be careful as you roll through because there are some things that you can do that might damage your system will point those out as we roll along so pay attention to those cautions so the first thing that you're going to want to learn how to do is figure out where you are and what you're looking at so the very first command that I'm going to teach you in the terminal is LS which stands for list storage and when you run that command and you run a command by typing it and then pressing the enter key it will give you a list of everything that is in the current directory that you are logged into the directory that you're logged into is usually your home directory and that is told to you right up front there by the prompt this is a boom - and this is pretty much the typical prompt that you will get and it tells you a lot of information first of all it tells you who you are which might sound like something that you should already know but there are occasions when it's nice to know that information and have it on the screen and it tells you exactly what computer you're logged into with bash you can use the remote shell or the secure shell ssh to log into other machines so if you have more than one terminal up it's kind of nice to know exactly what machine you're working in and then finally you'll see that little tilde character well that's an abbreviation for your home folder Tildy always represents your home folder and finally the last thing that you see is the dollar sign the dollar sign indicates that you are logged in as a standard user which means that you have regular privileges you cannot enter a command here and run it as an administrator unless you preface it with another command or you switch to the administrators account which is known as root so that's what the prompt tells you and LS tells you what files and directories you have with you before we go any further it's probably a good idea that we take a look at the basic Linux file system so that you can get an idea of what we're dealing with here this is called a tree it's upside down if you turn it right-side up then it would look more like a tree because we start out at root and root is the base of a file system on a Linux or UNIX machine and everything is in root which is usually a bunch of directories all directories are our files that contain more files so you can have files and directories in the root directory and then each directory can contain more files the one that we're probably going to be most interested in is the home directory that's where all of the users who have accounts on the computer have their files stored it's in there somewhere and that will make more sense as we roll along so LS shows us what we have in the current directory the next command to know is PWD where we can print the present working directory so PWD will tell you exactly where you are and in this case it gives us the full path this is not abbreviated so a path means that if you go from the root of the filesystem to wherever you are now this is how you get there so in this case we go from root to home to a directory called Joe and that is me directories and folders the names are interchangeable that's something else to keep in mind you may hear people refer to them as folders and that is because way back a long time ago in computer science class when they were first teaching us all about computers they likened directories to folders in a file cabinet so the hard drive would represent a file cabinet the directory would be the folder and of course files were within those folders so when you're working in a graphic user interface usually we call those folders because they're represented as cute little pictures of folders just to make sure that that's understood PWD tells you exactly where you are in the file system and gives you the full path that is called an absolute path there is also something called a relative path and a relative path is how you get to something from where you are right now and it assumes that whatever you're trying to get to is in your current working directory so in this instance I could for instance type in LS and then type in documents and I'm going to use a trick that I'm going to tell you about in just a second there to fill that up and now it will list everything in the documents folder and I used a relative path well I can also issue this command this way I can say LS route home Joe and then I can do do C type that correctly and it would help now I'm going to get exactly the same output and that is because I used a absolute path so you need to understand the difference between those two things so let's clear the screen here and let's issue LS again because I want to show you another thing that LS does and this is another important concept to understand about commands is that they usually have options so if I use a dash or a hyphen and then I give LS the a it's going to show me everything in the directory because there's more than what the eye can see some files and directories in Linux are hidden and they are hidden because they have a little dot character in front of them so there's way more in your home directory than you just see with plain LS and then LS has more options that you need to know about so LS and then the next command would be L what this will do is it'll give us a long list of everything which shows us all kinds of information about the directories if I issue that same command and now I tack a on there as well now I get everything in the directory don't worry about all that gobbledygook on the screen we'll talk about that as we roll along and it will start to make more sense so LS and PWD those are the first two commands that you need to know because it tells you where you are and what you have to work with the next command that I want to talk about is the changed directory command because this one's really important this is how you get from one place to the next so this will also show you the next concept that we want to get into which is called Auto completion so let's say that I'm sitting here at my home folder directory and I want to go to the Documents folder then I would use CD change directory and then I could just type in do C and it will autofill it for me when I press the tab key this saves you a lot of typing remember that people who work in a terminal whether they be programmers or sysadmin they're lazy we want to minimize our typing so there's all kinds of shortcuts in my original bash series I didn't cover Auto completion because the old-school way of teaching it is that you type everything but since then I have rethought that so that's why I'm introducing that concept now you will notice if I only type do and then hit the tab key that it doesn't do anything the first time if I hit it twice it now lists everything that could possibly be auto completed so it'll give you a list of all of the files or directories that you're looking for that you could use so in this case well let's change your mind we want to go into downloads so now I type a W autocomplete again with the tab key and now I'm in downloads once I'm there if I want to get back to the home directory I got a couple of options anytime you want to go up one level from wherever you are just put that dot dot in there and that tells the system hey I want to go one level up or in the case of the home directory I've got the ability just to type CD so let's go and we will go into downloads again CD boot CD with no argument basically tells the system take me home and also there's another way to do this which is rather redundant but it's good to know the home directory is abbreviated by that tilde so it'll do the same thing it'll take me home so that is the basics of how the CD command works and it's one that you will use a lot because you can move around the system so let me show you another thing about CD here and auto-completion together which makes life really simple so I'm going to go ahead and switch to My Documents folder and now I'm going to list the storage in there so oops I forgot to issue the command yep there we go all right I'm going to make typos as this rolls along I make a lot of typos while I'm typing and talking so please forgive me it will happen I know alright so here we are and if I just list the storage in here and if I scroll up you'll notice that we have some directories in here that have very long names with spaces and all that kind of stuff well dealing with directories and file names that have spaces in them can be a bit of a pain so this makes auto-completion really useful so if I want to CD into a directory I have called bash scripts and guides notice that it fills that in for me and not only does it fill it in but you see those little slashes there the back slashes those are called escape characters so if you are going to create or access a file that has spaces in it then you use those to tell the system yo ignore the space act like it isn't there and that will allow me to get into that directory no problem those of you who are already using a boon - may notice that my prompt is not showing the full path to where I am that's a modification that I have made boom - usually will show you the full path so on your machine it may say : documents and then it would be whatever directory you happen to be in to get back to the home directory boom there we go okay so that's the basic of basics of using CD with auto-completion one more thing thats related to CD that is very useful let's say that you are in your downloads folder type that correctly and you need to jump over to another folder on the machine which is way somewhere else on the file system so in this case we're going to be in et Cie well you could CD over there and then you could use a CD command to get back but there's another way to do this and the command for that is push D and then give it your directory and now what it will do is you see it's saying that we've gone from we've gone to the etc' directory into the Downloads directory and I can work here for as long as I like and then I can use a command called pop D and it get takes me back to right where I was yes you could use two CD commands why is that useful well what if you don't remember where you were what if you end up working in the et Cie directory for a long time and you go wait a minute what directory was I am I'm not really sure well if you use push D and pop D in that particular situation you'll always jump back to where you were and you won't lose your place you won't have to remember well what directory was I in to get that file well there you go so there you go that's how you navigate the system very basically so the next concepts that we want to get into is understanding what we're looking at so let's do that LS again and let's give it an a and well let's get into a directory that has something in it so I'm going to go back to my home directory we'll go to a well this which will show everything and now you see we have a list here and we're not really sure what we're looking at with some of these things Linux does not necessarily need or use file extensions especially when working at a command-line if you're coming from Mac or Windows you may be used to seeing extensions in on things like if you create a text file with a word processor it may have an extension called dock or in the case of Libre Office it would be ODT and that's telling you what kind of file it is what linux doesn't care it doesn't need those extensions to function it can figure out what a file is on its own so the next command that I want to show you is file so let's say for instance we don't know what that little dot face file all we've got to do is issue the file command and then give it the filename and it tells us that it's a JPEG image well what about that weird one that's you got now you notice I'm not going to type the whole thing we're using Auto completion now it tells us that that's a sound file as a matter of fact it says it's a WAV file so file will tell you what you are looking at well let's do that with one more just to prove a point file and let's do this thing here called SSR let's tell me that that's a directory which means it contains more files now in my terminal I get things color-coded which means that depending on what kind of file you're looking at you may have a different color that's very useful not every terminal that you sit down in front of is going to give you that lovely option so it's nice to know how to figure out exactly what kind of files you're looking at and that is file so the next thing that you're probably going to want to know is how do I find a file I mean there are thousands of files on this system and I need to look for a file somebody's telling me I need to edit such-and-such file and I have no clue where this file is well there's a several ways to do that but the easiest one there is in Linux is the locate command and it takes filenames or parts of file names so let's say that somebody told you that you had to edit the FS tab command or an file you have no idea where this is if you use locate and then you press ENTER it gives us everything that has the name SAFS tab in it now you'll notice there are a lot of references to FS tab and but the first one is the one we are really interested in which tells us that it's in et Cie and the locate command uses a database to find things so one of the things that you may have to do if you want to make it useful is update that database if you just installed Linux like an hour ago and you're trying to do something with the system chances are locate will not work at all because this database does not exist what Linux distributions do is they usually set the system up to update the database for lokay once a day so if it doesn't work today it may work tomorrow but you can issue that command yourself and then you can update that database so let me show you how to do that so locate becomes very useful to you we're going to jump ahead in our concepts here because I'm going to actually issue this command as the super user I'm going to have root privileges to do this because to run the update DB command you have to have root privileges so if you're working on a computer in a company or at school you may not have root privileges you may not be able to use this command this way you're going to have to ask your administrator hey update the database for locates so I can find this thing but if you're running your own computer then you should have administrative privileges so it's sudo update DB and it's going to ask for my password to make sure that I have authorization to act as the super user and then I get no output it actually does it if this command had never been run it was the first time that you were running it it may take it two or three seconds to run you won't see any output on the screen but when your prompt comes back you know that your locate database is nice and ready to go so the next command that we're going to take a look at is which and the which command finds other commands for us so if you know what a command is but you don't know where it is or you don't know if it's installed this is how you can find out so we will type which and in this case we're going to look for a little command called cow which doesn't do anything but print a calendar on the screen and tell you what day it is so if I do that it tells me oh yes it is installed on the system and it is in a directory called user slash bin slash Cal Cal is the name of the file so now that I know that that command is installed I can run it and it prints me a calendar it's a very simple command but it is very useful and it's a good one to know and the last one that I want to show you is history the history command shows you all of the commands that you've already typed what bash does is it keeps track of all the commands that you issue to the system and you can access that in many different ways I'm only going to show you two in this particular video but you can always look for more information about that you can use this in multiple ways so the first thing that you can do is just use your up arrow on your keyboard and it will show you the last commands in the order in which you type them so you see all of the commands I've used so far to demonstrate are listed here so if you type a command and then you go wait a minute hold on I don't remember exactly what I typed then you can just scan up your history and look for that command you can find it again now if you want to see what is in your history and you need to find a whole bunch of stuff then you can just type in history and make sure it typed it correctly as I did and if you press ENTER now it lists everything that you've typed in history usually keeps up with the last 1,000 unique commands that you've typed in and I'm going to show you a little bit later on in this video how to make this even more useful so if you don't want to sit there and look at them one at a time you can just roll up and down and then you can also issue these numbers in lieu of the command itself now if you want to find out how to use that you're going to use what I'm going to show you in the next part of the video to figure out how to do that so that is history and that is how that works so the next thing that you need to know about is getting help because there's plenty of help available to you and I'm only going to show you a few options for getting help there's a lot if you're sitting in a terminal and you're trying to figure out how to use the command or how to do something there's a lot of ways that you can get information without having to go to a web browser without having to have the machine hooked up to the Internet there is a lot of help information that is already here and all you have to do is know how to get to it so the most simple command is what is so if you want to know what a command does you're just going what is this what does it do then this will give you a very short little explanation so we looked at the Cal command which is that calendar command and it says it displays a calendar and the date that's it that's all it does so what is it's very useful if you're just trying to figure out what a command does and there's a lot of information and then there is another way to find out information about commands that you might not completely understand the syntax you may want to do something with the system but you don't know which command to use so be kind of nice to kind of give the system a pointer and say hey I want to do something that involves time but I don't know exactly which command to use well in that case you can use a pro PO and then we're just going to give it time now watch this we're going in a bunch of output on the screen I'm using my mouse by the way to scroll up and looks through that and so it shows us all kinds of different commands that are related to things that have to do with time very useful well if you need more intense information the next one to know and the one that I use more than any other command is just the good old man command man is he's your friend man so if you need to know what's going on you got to ask demand so how do you use man well the command is man and in this case I'm going to show you the manual page for the man command and then the page pops up now you can use the arrow keys to go up lines and scroll up and down you can also use the spacebar to scroll up and down through all of this information and you can read more about the command that you're trying to find information about not every command on the system has a man page like for instance I don't think there's a man page for CD because it's a shell function there really isn't one so you might not find one let's see if there is a man page for CD I don't believe there is no there's not because CDs pretty straightforward but there is a what is for CD I think ok so what is CD well see it's not in the manual so if therefore you can't figure that one out so every now and again you might run into something that isn't there but of course in this case you can always look it up online most of the commands that you're going to use are going to have a man page so therefore you can get to them from what is I propose or the man command so that's how you get help pretty simple huh I told you this was easy man it's not as hard as people make it out to be okay so the next part is working with files directory weirder ectly and we're going to work with files and directories directly I said it properly isn't that awesome so the first command that I'm going to show you is how to make a directory you might want to do this we're going to do this in this case we're going to call it junk so I'm going to make a directory called junk by the way if I wanted to make more directories I could just keep typing here it'll take input all the way until you get tired of typing so if you need to make a whole bunch of directories you could just do it all at once but in this case we're only going to make one for the video so now I have entered the command I got no output if you get no output that's how you know a command works and we're going to see if we've created our directory by running LS why yes we have that directory so let's go into that directory now we are in junk and our directory is very empty so let's talk about creating files I'm going to show you a really nifty command here called touch the touch command is more useful than it may appear touch does two things if you issue the touch command and then you do it with a file that already exists all it does is update the date on that file every file on your system has a little date a little thing in there that records the last time you accessed it or did something to it or changed it so touch will do that without actually doing anything to the file and it can be very useful when you're working with things like backup programs if you want to force the backup program to backup a file you could touch it and then it would have a later date than the last backup and it would just suck it on over but touch also has another curious function and that is if you touch a file that does not exist it will create that file there's nothing in it but it will create the file so in this case we're going to create a couple of files will create file1 file2 and file three and we'll turn touch loose and now we have created those files pretty cool huh make sure they're there there we go we have our files and they're in the directory so we can start playing around with these files now the first command that I think that people should know is copy because this is the one that saves your but if you have to go edit a file or you want to change something about a file but you want to keep a copy around this is how you would do it so copy we'll make a copy in the directory that you're working into so I'm going to tell it that I want to copy something from the home directory and I am going to give it a final name to work with in this case we're just going to pick a system text file that holds information we'll use this later on so there is bash RC ok and now we've got to give it a new name so I'm just going to call this bash RC without the dot so we know exactly what we're looking at so what I'm telling the system now is that I want to copy this file and I'm getting it from the home directory and because it auto-completed we know it's there so that's one of the things about autocomplete it's almost like LS without doing LS if the file if it autocompletes when you try and complete it you know the file exists and then I'm going to tell it to put it in this directory that we're working on right now because there's no path in front of the second file name boom there it is so let's see if we have our file in there so that's copy so if I was going to work on that bash RC file okay I would maybe want to copy it into something that would be a backup of that file so I could go back to it later okay so this in this case I'm just going to call it back and now that file should appear we're good to go so I can change things in my batch RC file and then if I screw it up really really bad I know that I have a copy somewhere and I can go back to the other one so the next thing that we need to learn how to do is to rename files we do that with the move command or MV MV has two functions it can either move a command from where we are now to some other place in the file system if we give it the name of the file we want to move and then we give it a path and another name it'll just take that file and stick it wherever we want it to go but in this case we are more interested in renaming a file so let us say that we did screw up our bash RC file so what we're going to want to do is we'll do bash RC dot back and we want to move this back in to bash RC alright didn't give us any output you're not going to see that it's done anything but if you had made changes to the original bash RC you would find that that file has now been moved and if I list the storage again look the dot back version of bash RC is no longer there that's because I renamed it bash RC I rewrote over the file and there you go I can also do the same thing here I can say I can move the contents of a file so let's take our same file that we've been playing with we'll do MV - and now we're going to move it into file 1 ok so now the bash RC has gone altogether but all of its context contents are in file 1 so that's using the Move command very powerful command and I suggest that before you start playing around with it you look at the man page for that one now we're going to look at removing files taking files away from the system this is the RM command and it is extraordinarily powerful this is one you need to be afraid of just a little bit because RM can be as precise as a scalpel but if you type it in with the right arguments you can blow away huge amounts of data and it just goes poof and unlike working in a GUI where you have a trashcan there is no way to get files back after you remove them with the remove command they are gone there is no undelete they just disappear it's one of the things that makes Linux very secure is that when you delete a file it disappeared it's gone it's going to be very difficult to retrieve that from the hard drive after you delete it so be careful with RN and the simplest way to use our M would be to issue our M against a file and then let's say we wanted to get rid of file - that would be it it would just go away a more powerful way to use RM would be to use RM and then use a wild-card which is something that you can do at a terminal if you want to refer to more than one thing then you can use a glob character which is an asterisk which basically tells the terminal I want to get rid of everything so the most powerful way to do that would be to go RM and the star what that would do is it would remove all the files from our directory and we're not actually going to do that but if I just wanted to get rid of files that have the name file in them I can put the glob on the end there and now what it does is it tells the shell it says ok I want you to remove all of the files that start with the word file and if there's any characters after that then they count - let's make a directory in here so I can show you the next thing about RM that you need to know and that is we're going to make one we're going to call it junk - so make sure it's there now if I run the RM command against junk - watch what happens says I can't do that it's a directory I can't get rid of it so if you want to get rid of files then you don't need to add any arguments but if you want to remove directories then you're going to have to give it an argument and that argument is going to be R M R and now if I would issue the star command it would literally take all of the files and directories out of there so what the arc command does it puts it in recursive mode which says remove everything in the directory including other directories and files and then remove the directory itself that is a very powerful version of RM and you should be just a little bit afraid of it okay so let's actually put our m to work here and I'm just going to get rid of file three because we didn't do anything with file three now the next command that I want to show you at first glance you may think well that's kind of redundant I don't need that but I'm going to show it to you anyway and it is the RM directory command or rmdir now what this will do is remember we put that thing in there that junk - or did I already get rid of it hold on a second let me see where I'm at here no it's still there so if I do our M dir and then give it junk - then it should remove that directory because there's nothing in it all the remove directory command does is remove directories that don't have anything in them if you have files in there it won't work you're going to have to use RM with the our argument there the recursive now you're saying yourself well how is that useful well if you have a bunch of empty directories you're working on a project and you've created a bunch of directories there's nothing in there you just want to clean things up a little bit then the rmdir command can be very useful so let's go ahead and create a bunch of directories and then we'll get rid of them in one shot and I'll show you how it's done so we'll make the IR and will call it dir 1 dir - dir 3 just a bunch of stuff all right now you see we have our all these directories in there I just want to get rid of there's nothing in there I'm done with them so if I do rmdir and then give it the glove it gives us some output because it's saying that file1 and file2 aren't directories but it still did the job watch all gone so that is the basic file navigation right there how you can manipulate files on your system and there's really there's more to that of course each one of these files has one of these commands that I just showed you has a lot of different options but you can look that up on your own and as you get more proficient you'll learn how to use those particular options well so the next thing that we're going to want to learn how to do is do something with these files other than create them and remove them what if we want to put things in them and one of the things that you're going to be doing at a terminal a lot is working with text files the entire Linux system or pretty much most of it all of the settings are contained in text files and to change things about your system or to fix things a lot of times you have to end up editing text files even the front end applications you use on your GUI are actually just editing text files in the background so we'll show you how to do that directly now as you recall I put some text in file one so there's actually something there and if I just want to see what's in there I will use the cat command let me go ahead and clear the screen here make it a little easier so we have the cat command and the cat command will just list everything in a bunch of files so if I give it file one and then I turn it loose it's just going to read the command and print it on the screen that's all it's going to do and it printed a bunch of stuff you can see everything that's in my bash RC file we can't really it's a long file so we got to scroll up here I'm going to show you how to deal with that in just a little bit but that's what it does so what if we had something in another file so I'm going to show you another thing that cat does I'm going to get a little ahead of myself and I'm going to open up cat and then I'm going to tell it that whatever I do with cat I am going to put into a file you're going what do you doing man this is really weird stuff believe me this is useful and it'll make sense later on but I just need to stick something in file to for right now so I've issued this command and basically what I'm saying is anything that cat comes up with I want it to stick it in this file okay so now I get a blinking cursor and I can type in hi and then I'm going to use ctrl D to tell the cat command that I'm done well what did I just do well let me show you let's cat file - well look it we printed exactly the same thing on the screen that's because I added text to it using the cat command itself this is one of the most basic things that you can do with a terminal like I said at this point this might not appear to be useful but if you need to create small little text files very quickly cat will do that for you so what else does cat do it sticks files together it's actually short for concatenate which means take a bunch of information and stick it in one place so if I cat file one and then I can't file - - until it file - watch what happens we have all the stuff that was in that batch RC file and then we also have all that information stuck down at the bottom so that's cat and it's more useful than you think it is let's look at some other ways to read what's in text files I want to introduce you to a couple of little programs called more and less more is very old and you're not going to use it a whole lot but without knowing what more is less doesn't make sense so we'll start with more so now if I say more and then I give it a file name I'm gonna give it file 1 there and I turn it loose look what happens now I can page through the file using the spacebar so I'm seeing it one page at a time all that crap that's in that configuration file when I get down to the bottom it returns me to the prompt that's more that's all it more does and if you issue more and then you go down to pages and you realize I don't really want to be here then you could do the queue use a queue and it will just dump you right back to the prompt it's all it does that's more that's it and it's a pager it just pages through a bunch of text in the terminal that's nice but there is a more advanced command that does the same thing so let's do less file1 the less command is more than more because now that we're using less I can use arrow keys and go down one line at a time I can also scan backup I can actually use the spacebar I can search for text within the file less does a whole lot of things so if you're having to read a text file and you're getting you know just overwhelmed by stuff scrolling off the screen remember to use less when you're done with less queue it lets you out so Q is for quit when you're working with less so there now you know more and less and you now though that less is more now we need to actually edit files and I showed you how to use the cat file to throw some text in a file and I introduced you to some concepts that you probably don't get it but what if we want to actually edit a file there are many many many many many text editors available for Linux but one that is probably the easiest to use and the most intuitive and it's going to generally be available on most Linux distributions that you sit down in front of is called nano nano is a very powerful little text editor so let's just give Nano a file name and let's just to keep this easy I'm going to give it file two and if you don't have a file and you just start nano and then give it a file name it's going to save with that phoneme I'll show you that in just a couple of seconds so there's a little file I created with cat and now I can use my cursor to come down here and type and change things and then down here at the bottom of the screen you'll see that we have lots of options when let's add something to this file let's just say let's just put let's say be ye write dy is like when you're leaving I'm going to throw that line in there and then with nano I use ctrl o to write out the file and it confirms the file name it tells me that I wrote it out and when I want to get out I use the ctrl key and the X and I'm gone so we can cast that file to see the changes see it added by so that's what it does it's a text editor now there are a lot of functions within there like you can cut text and then you can move things around you can mark things we're not going to get into that you can play with Nano on your own so if you just want to play with Nano just type in Nano and then enter and now you can do you know you can put whatever you want in here let's say hi and then if you want to leave you don't want to save it no problem just choose no and you're out you're gone it's pretty simple and pretty straightforward so Nano is an awesome file now before we move on from working with files I want to tell you about a little concept called redirection now I already showed you redirection with cat earlier when we created that file and that just means that I take the output from one program and put it into a file or into another program and this is very useful using these different commands so like I said with cat if I do cat and I give it that little bracket right there it's going to put this in a file file too if I want to append and not create a brand new file from scratch then I can use cat and put two in there and they below pin to the bottom so if I want to append to file two now we're just going to add the text to the bottom put in more stuff control D to tell it we're done there we go and then if I let's just use nano open up nano see I added more stuff on there so I appended to that if I did exactly the same thing and I only used one of those little brackets there we will do the same thing and then I'll just put in high this time and control D to tell it I'm done and now if I go back up here and Nano that file again look it's all gone because we created a new file so that's how you direct output from a program or from a anything that generates output on the screen you can stick it in a file that's what I wanted to say and the other way to do that is typing so I'm going to show you piping and that's taking the output from one program and sending it into the input of another remember our history command we looked at earlier okay so if I type in history it just Scrolls off the screen if I use the pipe character which on a u.s. keyboard is above the return key and you press shift to get it it looks like two vertical lines or a single line and then I'm going to put that into less watch what happens now I'm running less and I'm seeing the output from that command and I can page through it that's because I took the output directly from this command and put it into the less program when I used cat to create files I was taking the standard input which is your keyboard and I was sticking that directly into the cat program and then turning it into a file so that's the concept of redirection if you ever see that that's what that does and it's highly useful you'll find all kinds of uses for it so one last we're going to give you one last demonstration of redirection before we move on let's take the LS command I'm going to tell it I want to see everything I'm going to say I want to see everything so I'm going to give it all and I want a long list and I want to see that directory and then I want to put this into a file we will call that file watch what happens let me fix that putting you there so that makes sense LS out dot txt so what we're going to do is we're going to list the root directory and we're going to show everything in it and we are going to have a long list we're going to stick it in a file I saw actually nothing happen on the screen did it work we'll find out we'll do a LS and now you see that we have a file they're called LS out so let's LS or rather they're less LS out text look everything that's in the root directory but instead of putting it on the screen and put it in a file so that's basic redirection you have now been taught your life will never be the same once you know how to do that okay moving on so the next thing that we're going to do is jump to another concepts we've learned how to navigate the file system we've learned how to get help now we're going to talk about working with users and understanding how different users relate to each other on the system so let me go back to my home folder the first command that I want to show you is sudo we've already seen this in the video because it's something that you need to know sudo will allow you to do something as another user and most of the time with most modern Linux distributions sudo is how we give administrative privileges to a regular user so if you install a boon - or anything based on a boon - or debian or arch and you do not have a root account setup chances are you have a sudo account ready to go it's su and it stands for a substitute user do Super User do is another way to look at sudo some people call it pseudo that's incorrect but even I do that occasionally so you'll have to forgive me so how do we do this well if we have a command that we need to run as an element with elevated privileges we can just do this so in this case we'll run the update DB command as we did before and you get the idea it asks for the password and now I'm running this as the root user you can make sudo stick around you can become the root user and yes you'll see in a lot of Linux documentation that you can also use the su command which we will look at next the preferred method for doing this in a boon - based distributions is to use sudo s it is safer than su if you use the su command there is a danger that you may type in the right text and activate the root account if you activate the root accounts on an Ubuntu system or any system that has it disabled for security then the account becomes active and therefore somebody could hack into your system and get to it so in a boon to to act as the root user for a while you can just type in sudo and then s and you notice what changed there first of all it didn't ask for my password the sudo command runs a timer in the background so if you issue one command and a minute or two goes by you may be able to issue another command without it asking if that timer times out it'll ask for your password again that's for security at this case I am in this case right now I am running as routes so if I wanted to issue a command to the system as the root user then I would be able to do that now and I could issue one command after another to get out of this mode you type in exit and talk about exit a little bit more later Skype it incorrectly so it works and now you'll see that I've turned back into myself with the sudo s command it'll tell you that you are route and what machine you're at and you'll notice that this turned into a hash tag or a pound sign whatever you call that thing that's telling you that you're running as the root user and the root user has total privileges it is not a good idea to run as the root user all the time running as the root user can be dangerous you can type in commands and you can wipe out big chunks of the system or change things you can make mistakes here that will definitely mess up your system so be wary of running as root the RM command as root will erase anything on the system doesn't matter what it is system files makes no difference you can blow out just the whole thing so the next one that we want to look at is su and this changes you to another user so the su command works like this if I want to become another user on the computer let's say that I want to be Cyndi then I would type it with this syntax and the su command with a space than a dash and then Cindy what that says to the system is I want to become Cindy and I want to change over to her home directory and I want to load all of her settings in bash if I do not give it a dash then it won't do that I'll just jump in at Cindy but I'll still be in my own home folder so let's try it both ways and we'll see what happens so if I do this and then I'm going to put in her password and as the administrator on this particular system I have everybody's password I have access to it that's part of the fun of being the administrator you're all-powerful so if I do PWD over here you'll see that now I am in her directory so I have access to all of her files any command is you here will be as Cindy and it will operate in her section of the computer now to get out I type exit and then it says I've logged out and it dumps me back now if I do su and just do Cindy and I didn't put the dash in there watch what happens it's going to ask for the password it's saying that I'm Cindy but I'm in my own home directory so if you want to change something about Cindy's files I would have to navigate it to her folder manually here if I just wanted to run a quick command over here this would be fine but it's important to understand that that is how su works now I'm going to show you with su how to become the root user but I do not recommend that you do this with a boon to for the reasons that I previously stated however some distributions of Linux create a root user and if you have access to that account and you have the root users password then you may want to do it so if you just want to issue a command as root user you can just do su enter will attempt to log you in as root okay I'm not going to do it but that's how it does it if you want to become the root user and you want to navigate to the root users home directory then it is su and a dash with no name after it and that will take you you are now running as root on the system it does work in a boon too I don't recommend that you do it okay so the next thing that we need to know is how many how do we figure out who's logged into the system well that's really easy to do there's a couple of commands that tell you that information and this is going to be useful if you are on a system that's owned by a corporation or a school or let's say that you have a computer at home that has several accounts on it and you want to know if anybody else is logged into the system remotely or their account is active or whatever the deal is so we use users to tell me that and it says that I'm actually logged in twice because remember I have a GUI up and running and then I'm using a terminal emulator so I'm actually logged into the system twice if cindy was logged into the system from a remote shell for instance or she had left her account active and I had switched to it at the same machine then I would see that she was logged in as well so we can show that just by using that su and then I'm going to jump into cindy real quick I don't need to change to her environment to do this and we're going to ask you to Cindy it's going to ask for Cindy's password and I give it to the system now watch what happens when I do users well it's still telling me that I'm logged in myself okay hold on let's do it this way let's see if this works let me go ahead and get out of there let me switch over completely it may not tell me this may not work I may actually have to login from another terminal to do that let's try that again yep still logged in as myself because I'm actually just masquerading as Cindy she's not technically logged in if she was then we'd see her name up here but anyway that was a good shot and that actually taught me something about the users command that I didn't know that's cool see I learned all the time too just playing around with this stuff showing you guys stuff okay and the last command that has to do with users I'm going to show you is ID this gives you all of the pertinent information about your account it tells you what your ID number is and it gives you a bunch of information this can be very useful if you're trying to figure out why something doesn't work and what this is doing is just showing you the line that is entered in the users there's a there is a file that lives in the e.t.c directory called password and in the password it has all this information it's just spitting it back out at you in one line so for instance if you're trying to figure out why you can't move a file from one place to the other you may find that the system you're on has given you a different user ID number your ID number for instance might be 1003 and you're trying to move to 1,000 and it doesn't accept the input it just goes in permission denied I don't know who you are I know what's up it can happen so it's something that's kind of good to know right there is how to get this information quickly about any user like I said that is something that will become more apparently useful the more you get into the terminal okay I'm only going to show you one more command and then I'm going to show you how to kill some processes and you've actually got a really good start here for working and the terminal so there are a lot of options for users that I haven't shown you you can create users you can add yourself to a group you can do all kinds of things and there's lots of commands to do that and you can research them on your own when you're first starting out you're probably going to want to do those kind of things from the GUI I'm going to show you something else that you probably want to do from a GUI because it's available in every file manager just by going to the right-click menu and going on properties but it's nice to know how to do it from the terminal because you may find yourself having to do it from a terminal and it's nice to have a little bit of an idea of how to do it so let's talk for a second about file permissions so I'm going to go into documents and then I'm going to list the storage and I'm going to list it I'm going to make a long list here just show me all this information and you notice over here on the right-hand side of the screen that all of these files have all this gobbledygook right here and when you first start out there's a there's a dash and then it says RW and - and are these are file permissions and it's one of the things that makes Linux very secure is that every file on the system is owned by somebody and other people may or may not have permission to look at that file or do things with it and you have total control over that so when you look at a long list the first thing that you see here is the permissions and these are the links to the file don't worry about that that's something you can find out more about later becomes useful later on and then we have who owns the file which in this case is Joe and what group it belongs to it belongs to a group called Joe so these permissions right here the first three would be my permissions Joe as the owner the second would be group and the third would be everybody else in the world then it tells you the size of the file here and then it tells you the last modification date and the name it's all there so let us go ahead and clear this screen and we'll jump over here to another graphic that I have is going to make this really easy to understand when we're talking about all of this stuff so permissions are stored in three groups and each one of those groups represents a byte of data and there are seven bits within that byte and yes that is correct don't nobody type on there will abide is 8 bits yes it is but go look it up in the book I know what I'm talking about here there are 7 bits in a byte in this particular instance and each one of those bits represents a permission so the three basic permissions that we have that we can give to a file is that you can read it which means that some you can actually open the file and look at it and then there's the write permission which means that you can write to the file or you can delete the file you can change it in any way and then the last permission is X and that is your execute permission that means that this file contains code that the system can actually execute okay and we can set those permissions by assigning the actual bits that represent each one of those permissions in the groups so the first group there which is user which would be me in this case it is set that I can read write and execute the file read is worth 4 bits right is worth 2 bits and execute is worth 1 bit and we can use that knowledge to our advantage to change the permissions on any file in the system okay I'm gonna show you how to do that right now so if I have a file let's go into our let's get to our junk directory and we'll see that we have a list of files in there the stuff that we work tips are e there we go alright so let's do the list in long form and then we can see all the permissions so let's say that we have put a bunch of stuff in our file called file one we want to turn that into a program let's say that we have written a bash script and we want to make that executable so the system will treat it as a program well there's two ways that we can do that the first one is to use the change mode command or change mode we just skip the e and then we can use what is called a symbolic way of doing this which is usually the easiest way to do this when it comes to setting a permission to write execute so we just do + and then we do X and basically what we're telling the command is make this file executable for anybody and then we give it the file name next and in this case we're going to do file 1 and it took it so let's list the storage let's list the storage long ways so we can see the extra buttes then it didn't do it I know why it didn't do it - I knew I'd make mistakes King don't worry your mistakes you'll make mistakes - it used Capital accident didn't know what I was talking about now do it okay now list the storage and you can see that that particular file now has the execute attribute on it when you want to just make a file executable easiest way to go now that symbolic system goes on and on in my bash series I tried to show how that works and I have a mental block about making that work I got to be real honest with you I have never been able to use the symbolic syntax for the change mode command I just can't do it so what I do is I cheat and I use the numbers because it makes it so much easier so let's play around with this a little more let's do change mode and this time around I'm going to take those bits that I wanted to to show you guys about let's say for instance that I wanted to make a file here hold on it's not going to work glad I caught that okay it'll look stupid so if I put 700 in there what have I done well I'm setting the read write and execute bit for me and everybody else doesn't get no play at all when it comes to this file so we'll do that on file one because that's the one we've been working with boom and then LS the thing long and you see now that I'm the only person who can do anything with this file at all then I can change that once again by very easily let's say that I want to be generous now I want people to be able to read the file so but they can't execute it if I put four there because remember that the four bits represents the reads then it will work out right so let's do file and do file one and we'll risk the storage yep there we go and now I've made it so other people can read it but I'm the only person that can execute it that's it so you get the idea so whatever you put in there was going to do what you need it to do now most of the time you'll be working with these three numbers if you want people to if you want to be able to read and write to file yourself and you want other people to be able to read it then you can do 644 and what that's going to do is it's going to make it a pretty standard file permission there so you got to do LS LD there it won't work you guys so everything means gosh you can't type dude all right scene I always put it back to pretty much to where it was before Ubuntu by default by the way it creates permissions that give the group write privileges as well if you want to change that since it's how you can do it right here so the other one that you probably use a lot is 755 so if we go in here and change this to 755 now when we list it you'll see that everybody has right privileges but only you can actually write to and change the file one thing to understand before we move out of this particular session about changing file permissions very important that you understand this concept directories and files handle file permissions differently so if you wanted to create a file that everybody could write to no matter whether they were in the group or just everybody on the system that has access to the file then you could use 777 as it's illustrated here or you can make it restricted where people can only read the file and in that case it would be six four four four just write ability and readability six would be that meaning if you could read it and write as the user and then four and four would mean that the world and people within the group would be able to read the file that's how it works with files with directories you have to set the execute that if you want other people to be able to see that directory so when you're working with directories when we did the file 755 is pretty much the same thing as 644 is for a file if you do not set the execute bit on a directory for anybody else they won't be able to list the directory they won't be able to get into it they if you don't set the read bit they'll never even see it if you don't set the write bit then it's just like it doesn't even exist so it's a little bit different there so when working with directories you would use 755 and when working with files you would use 644 if that file happens to be executable code 755 would be the one that you would use the most yeah I know it gets a little bit confusing but that's kind of how permissions are even people who are advanced Linux users like myself every now and then scratch their heads because something doesn't work and you don't know why well that's why it it's because it's a little confusing but it's very secure that way okay so the last thing that we want to talk about before we wrap this up is that we'll show you some basic ways that you can kill programs and processes you want to be able to manipulate the system if you get into something you want to know how to get out of it that's the point that I'm trying to make here so the first one that I'm going to show you is how to kill a process that's running in the terminal you may type in something and you don't get a prompt you might run a command and starts doing something and you get into something you need to stop it and to do that you would use control-c - so to demonstrate that I'm going to use a command called watch what watch does is it basically reruns the command every two seconds so it's in this case will run the free command which shows us how much memory is in the system so we're going to watch free now basically every two seconds this is going to update and if anything changes it's going to tell me but you notice I have no prompt because this thing is just running and running to kill a command like that you use the control key and the letter C ctrl C kills a command it's dead it's gone so if you find yourself doing something and you know what's going on or something freezes up control C just may get you out of it the next thing that I'm going to show you is how to kill a command this is any process that's running on the computer so this happens all the time you might run a program and that program misbehaves for instance so in this case let's run Firefox I'm going to open up my Firefox browser and when it gets open here I'm going to stick it behind this terminal that we're looking at and you'll be able to see it through the terminal because I have a little bit of transparency on this terminal let's say Firefox it starts messing up on you and it's not working properly you can kill it and the Commandant will use to do that is kill all Firefox so if I you want to kill Firefox and this is a something that you started yourself you actually own this process you have the ability to use it it's something that you are kill it that's something you started as a user kill all only works for that you can't kill something that somebody else opened up logged in as another person there is a way to do it but you're going to have to figure out how to do that with super user privileges in this case it's just something you opened up Firefox has locked up doesn't work I need to get rid of it now it's gone it just went through and found every process that's running on the system that has to do with Firefox and it got rid of and it works with any application that you know the name of okay so you could use which to figure that out so for instance let's go back to the witch command and put in Google didn't find that let's find Google Chrome because that's another one that might lock up on you okay there's Google Chrome so if you're running Google Chrome and it locks up you want to kill it if you can open up a terminal then you can figure out exactly what command it is to use it in this case it's Google Chrome and then you would kill it that's simple actually I think that you can just put in Chrome and it will work there as well try on both ways if you actually want to use this to kill Google Chrome I had to kill Google Chrome not too long ago because it locked up and I think I just put it in chrome but you get the idea okay not trying to confuse you just trying to point it out that it might not work first time around you might have to play with it a little bit and the last thing that I want to show you is how to get out of a bash session so I've already showed you this several times but I want to show you what it does if you are logged into a terminal and you're done working you want to get out of that terminal let me just open up another one here and I want to get out of here there's a couple of ways that I can do that the first is to type in exit and this is the one that you're going to want to use if you're logged into a real terminal not a TTY or rather you're logged into a TTY or a real terminal I haven't covered that in this video but that's something you might learn about later on if you're using a terminal emulator or a teaching y you can always log out by typing in exit and in this case it just closes it up you can also do that by using control D which is the command that tells the system a I'm done with all the input and it'll just get out and it will close out for you if like I said if you are at a real terminal that's not a program that's running on a GUI like we're using here for the demonstration then when you log out it may log you out to a screen that just says log in that's so the next person can log in or you can log back in yourself the logout command also works but usually it recommends that you use exit so for those of you who have played with this for a long time there you go and finally every time I do one of these videos people ask about this so I'm going to tag this on the end and I'm going to show you some very useful things that you can do inside of the terminal when it's running at an emulator ok this these commands may or may not work at a real terminal these are mainly for an emulator but they're still quite useful so we've already talked about control D the next one is the control C command or rather control L which redraws the screen so if you have a bunch of output on your screen you just want to clear things off control and L will redraw the screen and it'll get rid of all the stuff and give you a nice clean blank screen you see me use that one all the time and then you can also change the text size in a terminal emulator and this works with most terminal emulators like and I know it works in Terminator it works in gnome terminal and works in xfce terminal pretty much anyone you're going to come across this will work so if you want to increase the text size you use the control and the shift key and that gives you the plus character and now it makes the text size big you see now it's filled up the screen and stuff it's going kind of crazy on me a little bit there okay well I closed my whole terminal let me open that back up again no got confused there or something let's do that again so to make the text larger you use the control key and the shift key to get the plus character on the keyboard and you make it pick and then to make the text smaller let go of the shift key and hit the - character and now the text will become smaller so that's how I make text bigger and smaller on the fly see if you don't hit shift then it'll show the equals and you know it's not working so let's go ahead and get out of that of course the command is not found so that's it gang there is your uh this is your crash course to the terminal we sat here and went through one lesson and I have introduced you to a whole bunch of concepts and I want you to go off and I want you to do research on this if you're new to Linux I want you to open up your terminal I want you to create a jump directory I want you to create files I want you to play and I want you to learn more about it because bash it's universal it's on every machine that you sit down in front of these days even Windows can run bash and if you know how to do it with bash you can do it anywhere that you go even on like little internet of things devices a lot of them you can log in and get a bash screen of some sort it usually uses a little program called busybox that has a few of the familiar commands in it but it's still you can manipulate the system that way you can do your router that way if you have access to it it's pretty awesome and there you go that is it thank you for watching the video I do appreciate it for more about Linux check out freedom penguin com also check out easy Linux on the web find out what that's all about and if you want a copy of this wallpaper that's on easy Linux comm you can look at that click on the thumbnail and then download it from there by saving the image and also check out easy Linux on facebook if you would and if you do that give it a like I certainly would appreciate it thank you for watching I hope that you found this video useful and if you did please share it I would appreciate it
Info
Channel: Joe Collins
Views: 2,203,798
Rating: undefined out of 5
Keywords: Linuc, BASH, Terminal, Software, Computer, Desktop, Laptop, Tutorial, OS
Id: oxuRxtrO2Ag
Channel Id: undefined
Length: 74min 37sec (4477 seconds)
Published: Thu Mar 02 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.