Bash Basics Part 1 of 8 | Access and Navigation

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
greetings and salutations and thank you for clicking on this video this is the first video in a series that we're going to do and we're going to talk about using bash in a terminal and this series of videos is intended to take you from the very basics to some more advanced things as we roll along I plan on doing this in several parts so that you won't get overwhelmed with one big long video and you can watch the videos at your own pace you can watch one go off and play with it for a while and then move on to the next video for more advanced concepts what is bash it is a shell basically it stands for the born again shell shell is a command-line interpreter which means that it provides a way for you to type in humanly readable commands that get the computer to do something in Linux pretty much the default shell these days is bash it's on every Linux distribution that I have ever used it is not the only command-line interpreter available for Linux you can have corn you can have seashell you could use SH yeah you could use many different shells a really cool one to look at if you're very much into it is fish but today we're going to talk about bash because it's universal it's everywhere it's not just on Linux it's on Unix it's on Mac and you can even have bash on your Windows system so bash is becoming a universal language that you can use to run just about any computer in the world in this day and age when we have all of these graphic user interfaces why would you want to actually have to type commands into a terminal it does seem a bit archaic but it is very efficient you can do things at a terminal much quicker than you can using gooeys where you have to point click wait for it to load find the box to click that sort of thing in bash you can just type in two or three different come ends and the system goes off and does what you wanted to close it up and you're done so the first thing we're going to talk about is how you access bash and in Linux the most obvious way to do it is to open a terminal emulator which is what is open here on the desktop we are using a boon to Ma Tei 1604 in our example here but a lot of what I'm going to tell you is completely universal and if I do issue a command which I think is unique to a boon - then I will let you know but whatever distribution of Linux you happen to be working on you can open up a terminal each desktop environment has its own version of a terminal emulator so if you use an own base desktop like cinnamon or unity or gnome proper then you are going to have the gnome terminal if you're using xfce it will probably be the xfce for terminal you can have as many different terminal emulators as you like a boon to mate' comes with a nifty one pre-installed called tilde and tilde runs all the time it boots up when you login to your account and it logs you in and all you have to do to access it is press f12 tilde is a nice thing to have around because at any time during your session if you want to jump into a terminal and check something out just press f12 type in your command let's say I want to know what date it is even though it's listed up here in the upper right hand corner I can get bash to tell me by issuing a command so it's very useful to have around indeed there are other ways to get to a terminal on your system instead of using a terminal emulator you can get to an actual terminal also known as a TTY back in the early days of computers when you had large computers that filled up whole rooms you would access that computer by using a teletype machine that's why they're called tt wise and the Linux system automatically spins up eight TTY zat boot and it usually puts the desktop environment on TTY seven so if you were to issue the command to get to another TTY while you were watching this video your desktop environment would continue running on TTY seven you would just switch away and your screen would have something up on it that looks like this and then you could switch back you can be logged in to all of the TTY is at once if you want to and each TTY could be doing a different operation so to get to a screen that looks like this alternate to control and any of the function keys f1 through F will take you to a different TTY in this example the fella who took this image he is using a boon to 12:10 and he is currently on TTY 3 and at login you put in your password and or rather your username and then your password and then you are logged in to the system and this is what you are going to be looking at to get out of a TTY you can switch away from it or you can just make sure that you log out of course because you don't want to be sitting here logged in if the machine's going to continue to run and you do that by typing in logout and then it will put you back at the prompt for the next person to log in then use alternate ctrl and f7 or f8 depending on where your distribution put the actual desktop which TTY it uses to get back to where you came from why would you want to use a TTY what happens if your GUI interface stops working or maybe somebody else is logged into the computer and you just want to sneak in there real quick and execute a couple of commands and get out you don't actually have to log into the desktop it can be sitting at the login screen at the Desktop Manager window and you can still gain access using a TTY so if the desktop breaks and you need to troubleshoot it or you need to restart the computer your desktops totally locked up you can always do it from a TTY so that's why knowing how to get to a TTY is very useful and in my case I use TTY is all the time to run updates on the machine and things like that ok so let's go ahead and get out of the - manual page there and now we look at our screen and you'll see that the only thing I'm presented with at this point is a prompt I'm going to clear that you can also clear your screen by using ctrl + L if your terminal supports it some do some don't most of the terminal terminal emulators certainly do but clear will also clear your screen all you got is this blinking prompt there's nothing else here how useful it's this it doesn't tell me what to do obviously to use bash you need to do a little research first and learn some commands and learn some navigation tools so what does this prompt to tell us it tells me that I'm logged in as Joe that's my account and that I am running on a machine called a machine that is the local machine that we're on but if you use a program like SSH the secure shell to log in to another system this prompt might tell you that you're on another computer across town or halfway around the world then you will see here that we have this little tilde right there and that tells us that we are in our own home directory that we are in our little space here on the Linux system and the dollar sign tells us that we are running with normal user privileges we are not running as an administrator and we cannot issue administrative commands will talk about permissions and privileges a little bit later on in this series right now just just know that the dollar sign is telling you that you're running as a normal user so one of the basic concepts that you need to understand when you first start working with bash is that bash expects you to be somewhere in the file system of the computer at all times which means that you are always somewhere and your prompt will tell you where you are but if for some reason it doesn't and you get confused and you just really can't figure out what you're doing here then you can use the first command I'm going to show you which is PWD which stands for present working directory or print working directory I've heard it both ways and when you type that it just simply puts some output here that tells you exactly where you are in the file system let's take a moment and talk about the Linux file system so that you get a concept of basic concept of how this works so we have here an image of the filesystem tree and it is important to note that no note upfront that there is another use for the term filesystem besides what I'm talking about here a filesystem can be one of two things it can be how the system organ 8 organizes files and directories or it can be the system that is used to write data to a hard drive so you'll hear filesystem used both ways ok and the other thing that is used in two different ways is the concept of root you will hear about the root user on a Linux system and you will also hear about the root of the filesystem the root of the filesystem is represented by a slash that means the beginning of the filesystem everything else sits in the root folder and a filesystem on Linux can include many different storage devices it can also include Network shares that hook it up to computers all over the world so a filesystem on a Linux machine is very much different than what you're used to let's say on a Windows machine where you have drives and they're a B C and D and each Drive has its own file system and you're worried about what drive you're on in Linux we don't care what drive you're on at any given time and this allows it to be very scalable you can have a very small system like we're using here a small desktop machine or you can have a huge system with many different computers and lots of different users and everybody accesses the file system in exactly the same way some basic directories that you will find in the file system and by the way the word directory and folder is interchangeable in computer science class years ago they taught us that a directory was a file that held a bunch of other file sort of like a folder in a file cabinet that you could put individual pieces of paper in and you could even put more file folders inside a file folder so those terms are interchangeable depending on how you're using it usually if you are working in a GUI environment and you are looking at a folder in your file manager we call it a folder and if you were working at a command line then you call it a directory but it's exactly the same thing so directories are folders that are very important in the Linux system in this this particular graphic is simplified there's actually a lot more in here and I'll show you that in just a few minutes but these are the ones that you really as a user need to know about and know they're there so we have the route up top and in the route we have the first one listed is etc' or Etsy and in the Etsy folder that is where configuration files for the system itself are held so if you're going to change some sort of parameter about the entire system using administrator privileges you may find yourself editing a file in the Etsy folder the dev folder stands for Devices and that is every device on your computer everything that is hooked up to that computer is represented by a file in the dev folder your hard drive your mouse your keyboard everything in the UNIX and Linux world everything is represented by a file regardless of what it is even running processes on your computer are represented by files so they have to have someplace to be so it's the dev folder the home folder is where all of the user information is kept when your account was created your a folder was created within the home folder so in this example we have a folder for Cori there and maeko and jono and then it shows that all of your photos and documents and everything are in that individual folder that folder is yours you have permission to look at change modify delete add to everything in that folder because it is autumn radically yours and that is where everything that has to do with you lives on the system you can have one user on a Linux system or you can have hundreds of users on a Linux system it all works the same way the next folder to talk about is universal system resources or user USR and here is where files and folders are kept that affect the entire system for instance your desktop may store all of its themes in there so when you're switching themes those themes actually live in the universal system resource folders some programs that you install on Linux the binary executable file goes there so that's an important folder to know about and also within that folder is another folder called Lib which is short for libraries and that's where important files that applications use to gain different functionalities are stored and so every now and then somebody will say well if you want it to do that you're going to have to install this Lib file that's where they go or at least most of the time and the last one here to talk about is the VAR directory VAR is where all of the logs and temporary data for your system goes and sometimes if you're trying to troubleshoot a problem you may need to go look around in the VAR directory and look at a particular law to see what the system is doing so that is a basic rundown of the Linux file system so we're going to go back to our terminal here and go ahead and clear the screen once again and we're going to start learning how to work your way around the system now in this video we're going to look at the very basic commands and before we move on to more you know advanced concepts we're going to take a break so almost at the end here kids just a few commands to talk about here so you can start poking around your system and seeing what's in there and the very first one that is you're going to use a lot is LS which is short for list storage and this shows you what is actually in whatever folder you're in remember I showed you present working directory that shows you exactly where you're at in the file system here's how you see what's in whatever directory you are in so if I type ls' and then I issue a slash that means I'm going to now look in the root folder and it's going to show me what's in the system so we get as you can see we have a lot of the different directories that we just talked about and there is more to it to get back to your home folder all you have to do is type cd' you do not have to give that folder or rather we haven't covered that yet but we'll cover that in a second we're still in our home folder now let's talk about moving from folder to folder so let's say we want to move to the root folder the command is CD got a little ahead of myself there if we want to get back to our home folder all we have to do is type CD it takes us right back also you can use CD and then you can hit the Tildy and it will take you to your home folder but CD with no argument will automatically take you to your home folder now let's talk about changing folders here let's LS once again and let's say that we want to look and see what's in the music folder so change directory music and keep in mind that when you're typing commands in a terminal it is case sensitive so if I type music it takes me to the music folder alright so let's list the storage and now we see we have one called pop however if I do CD and then I type in pop but it's not capitalized it's not going to let me in there because it's not the same thing those of you who have fond memories of working with DOS may be kind of befuddled by that because in the windows world the case doesn't matter and makes no difference you can type in P o P in fourteen different ways and it will always take you to pop or rather you know whatever combination of capitals and lower cases you can put together I don't know if there's 14 but anyway so let's get back into our home folder this is how you would look around in the system let's take dive a little bit more into the LS command because it does more than just the files that are in a folder if I type in LS and then a it'll show me if there's any hidden files in that folder and there are and in Linux and UNIX to hide a file you name the file by placing a dot in front of it and that's how you make it so it doesn't automatically show up in a GUI let's go ahead and do this and I'll show you how this works I'm going to open my home folder here in the file manager and you'll see that I'm seeing all of those folders if I want to see the hidden files ctrl H now I have can see all the hidden files and folders in that directory so we're doing the same thing here by just issuing an A at the end of the LS command but there's more if you want to not only see what's in the folder but you want all the details about it then we can do LS and give it the option a and we'll also give it an option l and when I do that now I'm going to get this big long list of things and it shows me all kinds of stuff about the different files and folders that are in this current directory over here on the left all this gobbledygook it shows you the permissions that are attached to the folder or the file we'll talk about that more later on in the series it shows you who owns the file in this case it is me Joe this file is owned by root which is the root user of the system or the super user and what group does it belong to well it belongs to Joe so anybody in a group called Joe can have access to this file then there's the creation date the site the size here the creation date and the actual name of the file or folder very useful to learn what LS can do so let's go ahead and clear the screen ctrl L and we're going to start to learn how to manipulate files we will create them ok so let's first make a directory so we have some place to play we're going to call this directory junk so the command to do that is make dir make directory and we'll call it junk and we'll leave it all lowercase just so I remember not to you know that I make sure that I can get to it because I'll forget let's see if it showed up well yes there it is so let's jump into our directory we call that junk now even though it's showing us let's get the full path to where we are not PW PWD and now you see that I'm in slash home slash Joe slash junk and at this point before we do anything else let me explain the difference between an absolute and a relative path so if I wanted to get that to this directory or another directory like it let's go ahead and switch to the root directory very quickly okay and I am in route now and you'll see that there's the home folder if I want to go back to the junk folder that I just created then at this point I would have to type in what is called an absolute path I have to tell them system exactly where it is so we're going to go home Joe and then junk so now I've given it the entire path from the root of the filesystem and now I'm back in junk however now that I'm already here I don't have to type all that in so I can just tell the system if there's another directory in here let's just go up one directory you notice now that I'm not having to put the entire thing in there so if I want to jump over to music once again it just takes me straight to it because it is a directory within the directory I'm working in that is called a relative path alright so that's the difference between an absolute and a relative path all right let me show you another little groovy thing here this is a command that you don't hear a lot about but I actually get a lot of use out of it so let's say that you're working in the file system and you want to be in two directories at once you want to just switch back and forth between the two well you can use assist a command called push D and I'm going to tell it that I want to be in slash home Cindy D all right so I'm actually going into another users directory here to show you this and here we go and now I'm in that directory now let's say that I was somewhere else in the file system doing all this work and I just want to jump back to the directory I was just in so now is you a command pop D and it puts me right back where I was so I don't have to issue an absolute or relative path to get anywhere it's pretty cool to know that not very many people know about the push D and pop T pop D commands all right so the next thing that we want to talk about is manipulating files we want to do things with files so the first thing that I'm going to do is jump into our junk directory that we created and we're going to put some files in here files are usually created by programs so you think about your word processor it saves things as a file if you record audio it saved as a WAV or an mp3 and a Gore something like that and the program itself generates a file but how do you create a file if you need to well you can use a program but if you don't have a program around you can still do it one of the very flexible and surprisingly useful commands in Linux is touch and the touch command if I type it correctly we'll create files so we're going to call this one file one and we're going to turn touch loose LS to see if it did it and now we have a file one and a file to you we have a file in there you can also get touch to create more than one file at a time so let's create file two and file three using the touch command done and now we have three little files to play with right now these are just empty files there's nothing in them and but you might find this useful if you're going to need to create flag files for things or you just need to create an empty file to start with somewhere and that is the first function of touch the second function of touch is to modify the date on an existing file so let's say for some reason that you have a file that you haven't accessed in six months you want to make sure that your backup program grabs it because usually the way those programs work is they look at the access or the modification date on a file and they go okay this has changed we'll back it up so I can use the touch command on an existing file doesn't give me any output but if I do an LS and I do a long list there we go you'll see that the time on file 1 is actually now newer than the other two files I created so that's what touch does all right and clear the screen again so we have our files created what can we do with them well first of all let's talk about getting rid of a file this is a command that you need to be just a little bit wary of because unlike working in the GUI environment when you click on a file and hit the Delete key or choose it from a right-click menu it doesn't go to a trash can there's no trash can in the world of bash so once you delete something it goes away and the command is RM for remove and we're going to remove file 3 no output means that it did what it was supposed to so lets LS and make sure that file is gone so now we have two files in there and the next thing that we need to talk about is a command that will allow us to change the files name and in this case we use the Move command or mV we can use this command to move a file from one directory to another or we can move the same file to another file name so let's say that we want to change file 1 and we want to change the name of file 1 to file 1 dot txt all right no output means it did it LS to make sure it was done all right so now we know how to create files we know how to remove them we know how to move them around and so we're getting somewhere we're actually doing something with the computer I realized that at this point you're probably going how is all of this useful but these are concepts that you absolutely have to know here so before we get out of here let's talk about using the Move command to move to another directory alright so let's create another directory within our junk directory here and we'll call this one files execute LS there's our directory it's there and now we want to move the text the file one text to that directory so we use M V and now we are going to just say that we're going to put it let's see go ahead and put the name in make sure I do this correctly don't do this every day you know we're going to we're in a relative path so I can just put actually we need to probably use an absolute path here so let's do home Jo junk all right and we want to move it to the directory files and if I put that extra slash on the end it it's telling that it's telling the system that I just want to move it into the directory I'm not going to try and change the name of the file to a directory name which it won't let me do so let's see if this one works well it's not going to work if I let's type things dyslexia is a terrible disease so there we go now that command should actually work and it didn't give me any output but let's see if it's here well it did something with it let's go into files and LS yep it moved it there so that's how the move command works and everything that you need to know about the move command back to my home directory now here's a very important command and that is we're going to learn how to remove a directory this is one you need to be very very very careful with because if you issue the wrong command on the wrong directory you could make your entire home folder go poof so do be very careful when you're using this command so RM with the option R makes it recursive and then we're going to remove their directory called junk and everything that we just did is gone so there is your basic first Primmer about navigating the file system changing paths creating files and the leading files in the next video we're going to talk about putting things in those files thank you for watching and be sure and check out easy Linux on the web check out easy Linux on Facebook and if you would give it a like and also check out freedom penguin comm for lots of great articles about Linux from contributors like myself and many others stay tuned for the next episode
Info
Channel: Joe Collins
Views: 194,442
Rating: undefined out of 5
Keywords: Linux, Bash, Tutorial
Id: eH8Z9zeywq0
Channel Id: undefined
Length: 30min 42sec (1842 seconds)
Published: Mon Apr 11 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.