Linux Essentials: Navigating the Linux Filesystem

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello and welcome back to learn linux tv i have another video for you guys in my linux essentials series and for those of you that are new to this series each episode in this series is completely standalone you don't have to watch all the episodes that i have in this playlist but the purpose of this series is for me to teach you guys the basics in each video i dedicate the entire video to one subject and then i teach you the basics of that subject in today's video we are going to explore the concept of file management we're going to explore the linux file system all the directories that it contains and we're going to take a look at how to navigate it now before we get started though i do want to mention the sponsor for today's video lenode lenode has been doing cloud computing since 2003 which is actually before amazon web services was even a thing on the node's platform you can get your server up and running in minutes and they include all of the popular distributions such as centos debian ubuntu fedora and get this also arch linux and let's be honest what could be better than a linux cloud server provider that allows you to tell all of your friends i run arch lenod has multiple server plans available to make any app scalable and flexible you can use it to host a blog set up a vpn server a minecraft server or you could do what i did and set up a website for your youtube channel because the official website for learn linux tv runs on lenode and lenode offers 24x7 365 support regardless of plan size so you can get live help from a real person when you need it new users can get started right now with one hundred dollars in credit towards a new account and i highly recommend you check them out because lenote is awesome i would like to send a special thank you out to lenode for their continued support of learn linux tv i really appreciate it now with that out of the way let's go ahead and dive into the topic at hand all right so let's get started now here on my screen i have a debian instance set up on lenode that i'm going to use for the examples in today's video however it doesn't actually matter if your instance is on lenode or some other provider because well we're going to be looking at concepts that are not specific to the underlying hypervisor we are looking at linux file system components and that's going to be the subject matter for today's video first there's a couple things that i think you should be aware of for one i often use the terms directory and folder interchangeably so keep that in mind they're essentially the same thing but in linux it's a little bit more complicated than that but i'll spare you the specifics of how that's different since it's out of scope so when you hear me mention directory or folder i'm referring to the same thing also it's important to understand what i mean by file system when i use that term in this video and the term file system has two meanings in linux which can be a bit confusing the first meaning of the word filesystem is a system on your hard disk that defines how data is written to and retrieved on windows popular file systems are fat ntfs and so on in linux we have ext4 among others but when i say file system in this video that's not what i'm talking about i am not talking about the way that data is structured on your hard disk but i'm actually talking about is the default layout of the directories on your storage media again it's the default layout of directories on your system linux has a generally agreed upon definition for each of the folders in the file system and what they're for and we'll get into that in more detail here very shortly and i'm going to show you the file system shortly but before we do the first command that we need to know is ls and here it is and here you can see i have a file and a folder now generally speaking folders are often colored blue in linux you can't always rely on that though and that's because colorization when it comes to ls output is a tweak not necessarily the default on everything but it is often the case but what i like to do is run ls-l which will list the storage in a long list and we get quite a bit of information here so first of all we have awesome underscore file.txt that file was created on february the 22nd at 22 57. and then we have this directory right here called characters that was created around the same time so already we have discovered that the ls command gives you a listing of the contents of your current directory and ls-l does the same thing but gives you even more information like the dates and times as you see here but we also have a permission string for each item on the left hand side now we are not going to talk about permissions in this particular video the only thing that you should remember is that this group of characters here at the beginning for each item is the permission string for each item is how you know what the permissions are of that item and i will go over linux permissions in a future episode of linux essentials but that's enough about that for right now now the reason why i mentioned the permission string here is because it's more than just a way of knowing what the permissions of an object are and yes that is the main reason why we have that the first character actually tells us what that item is now here we have d for directory as the first character in the permission string the d stands for directory so even if we didn't have the blue colorization here we would still be able to determine that it is a directory and not a file if you are coming from a windows background you are probably very very accustomed to seeing file extensions like txt however in linux you don't actually have to have a file extension to be fair you don't have to have one in windows either but linux is able to tell what type a file is even without the extension so i created.txt as the extension of that file name just for the sake of etiquette but here we have a hyphen as the first character which tells us that it's a file and then here we have d for directory now i've mentioned that the ls command is how we list the contents of our current working directory but what exactly is our current working directory actually it tells us right here we have a tilde character right there and that is shorthand for the home directory so anytime you see the tilde when it comes to a path in linux is automatically referring to your home directory but actually our current working directory is not tildy if i use pwd to print the working directory we can see that the current directory that i am inside of is slash home slash j that's where i am in the file system right now so if i was to do ls against slash home slash j just like that we see the same contents as if i was to run ls by itself why because the ls command if you don't give it an argument of a path will list the storage for your current working directory but you can also give it a path if you wanted to actually look at the contents of a different directory somewhere else so for example i could take off the j right here and just take a look at the slash home directory by itself and as you can see inside there i have a folder called j now the home directory is not the beginning of the file system though you can already tell that because my home directory called j which is typically the same name as your username and the username is typically shown in bash as the first part of your bash prompt and the home directory for your user is generally going to have the same name as your user now when we actually talk about the beginning of the file system what are we talking about what we're talking about is where everything begins so if i was to do ls-l you already know i'm in my home directory and it's going to show me the contents of my home directory if i was to use that same command against a single forward slash what would happen then and as you can see the output is quite different isn't it we have quite a few folders here now i'm not going to go over each and every single one of these items here in this video because that's beyond the scope i'll be getting to this in just a moment but i wanted you to know that the file system actually begins with a single forward slash but just like you would refer to the operating system drive of your windows installation as the c drive the beginning of the linux file system is a single forward slash so if i clear the screen and i did so by holding ctrl and pressing l let's take a closer look at how this is laid out so again pwd that prints the current working directory let's actually look at this path right here this directory is where i currently am in the file system and if you have a home directory on your linux instance then typically when you open a shell you are going to start in your home directory and we have slash home slash j so this slash at the beginning is very important so if i was to run ls dash l against home slash j just like that it's not going to work why because there is no directory named home inside my home directory if i was to recall that command and actually add the slash at the beginning it's going to work why because i am telling the ls command to start the search at the beginning of the file system the forward slash and there in the root file system there's a folder called home and underneath that folder is another one called j so let's walk through that so ls dash l and then a single forward slash which you've already seen is going to list the contents of the root file system you know the beginning if i scroll up here we actually see a folder called home so that's actually where we were so i could type cd for change directory and then a single forward slash and that's actually going to change my current working directory to being just slash as you see here so if i list the storage again and i didn't use the dash l option this time but it doesn't matter you can see all the contents of your root file system and then i can go into slash home we see the home directory right here so i'm basically telling the cd command to start at the very beginning of the file system and then change into a directory called home and we do have one right here and now my current working directory has changed to slash home as you can see and now you can see right here i have a home directory so let's go in there now notice that immediately my current working directory which is normally shown right here in your batch prompt has changed to a single forward slash so if i was to go back to the root file system and then cd into tilde as you see here that basically brought me to my home directory so again the tilde is shorthand for your home directory now let's take a look at some of the things that we have here in my home directory i have a file right here called awesomefile.txt and then i have a directory called characters so let's go ahead and see what's inside that awesome file and i can use the cat command short for concatenate to view the contents of a file and there are other commands that you can use to view the contents of a file as well that's beyond the scope just keep in mind that when it comes to linux there's always more than one way to do virtually everything and that file contains linux is awesome and well that's one method that we can use to view the contents of a file but i also have a directory called characters and i bet you're curious as to what i have in there so i will cd into that directory and what i did just now is i typed cd space and then a few characters of the directory and then i press tab if you have typed enough characters of the object you can basically press tab to auto complete that which i did right here and inside that directory we have a text file called batman and another one called tmnt so if i cut out the contents of batman you can see that it contains that and then the file tmnt as you can probably guess has the names of the four teenage mutant ninja turtles and why did i use that as an example well if you can use ninja turtles as an example for anything you probably should anyway those are some examples of moving around the file system you saw the ls command quite a few times that's how you can list the contents of a directory and then we also used cd to change directory now let's go to the root of the file system and let's have a chat about some of these directories here these default directories and what they're for and why are there so many now i'm going to go over the more important directories on this list it's beyond the scope of this video to go through all of them in fact there's an entire pdf i think it's something like 40 pages it's called the linux file system hierarchy standard it's a standards document for the linux file system providing a definition for each of the directories and a lot of the subdirectories that you could find on your typical linux system and the purpose for each of those directories and i'm not going to read that entire document to you i think that would probably put you to sleep but again i'm going to go ahead and go over the more important directories that we see here now first of all i mentioned that if we have a d at the beginning of the permission string then that means that object is a directory and i also mentioned if it has a hyphen or dash at the beginning then it's a file so what the heck is this it's an l well that actually implies that the object is a symbolic link and you can see here that it's a link called bin and it points to user bin now i'm going to save symbolic links for another video so the takeaway for now is that l is link moving on from there we have a boot directory this is one of those directories that you should never mess with unless you have a very specific reason to do so and the boot directory just like the name would imply actually contains very important files that allows your system to boot so if you start messing with the contents here and you make a mistake well guess what your linux installation may not boot when you go to restart it moving on from there the etsy directory is a very important directory that is where your system-wide configuration for applications is stored and the etsy directory is often a target for backups as it should be because well important configurations are stored there so as you get more into linux you'll understand that you have local configuration files you also have system configuration files in your home directory we're not going to get into this right now but you're able to actually store config files for your user in your home directory and if you do that then those settings apply only to your user but settings inside the etsy directory that actually applies system-wide so let's go inside and have a look around we have quite a few objects here don't we now i'm not going to go over all of these here because that would take a long time but we have a lot of configuration files here that are very important to our system if you are working with a server and let's say for example you set up a web server you want to serve a web page from your linux server then the configuration for that web server is going to be stored here and if you back up your etsy directory and something happens to your server then you can easily restore the settings for your web server and that's one of the many reasons why you would want to back up your etsy directory and what i'm going to type now is cd dot dot which basically means go back to one directory below where you are right now moving on from there and the home directory we have already talked about but what's interesting though is i have mentioned that each user has his or her own home directory and as you can see here i only have one user on my system but wait a minute if you didn't already know all linux systems have a user called root root is essentially the god mode account of linux as well as unix the root account can do everything and i mean everything even to a fault the root account can even delete the entire file system in one shot if you are so inclined to do so which is why people generally don't run is root but we know that we have a root user on the system because well all linux installations do but there is no root folder right here there's no slash home slash root for that user and why is that well actually we have root's home directory right here and root's home directory is not inside slash home root has its own directory at the root of the file system so this is actually the home directory for root right here and if you are curious where the home directory for root is well now you know so i've gone over home [Music] and we haven't gone over media and we haven't gone over mnt either both of these directories media and mnt have a very very similar purpose they're both used for mounting external storage systems and even internal storage systems so for example if you were to attach a hard drive to your linux installation maybe the current hard drive that you have isn't big enough so you want to add a second one which you can do you have to have a place to mount that directory there's no d drive e drive f drive and so on everything starts at a single forward slash so you would actually mount that hard drive to a subdirectory of mnt or slash media and we can cover mounting storage volumes in another episode but generally speaking both the media and mnt folders here at the root file system serve the same purpose for mounting storage volumes and you can also use them for mounting storage on a network share such as nfs samba on windows and so on if you were to mount a network share you would also mount it at a subdirectory of one of these two but which one would you use and for which purpose now it's actually a little bit more complicated but i'm going to simplify it down as much as i can the slash mnt directory right here is actually for permanent storage and i'm going to use permanent and air quotes because nothing is really all that permanent but i mean permanent in terms of you want to attach a storage volume to your linux system and you kind of want to keep it around for a while for the foreseeable future so for example if you were to add a second hard drive then you would probably do that under mnt you would create a directory underneath that and then you would mount it there again out of scope just keep in mind that the mnt directory is for things that you generally want to keep around for a while and a network share would also fall into that category as well because if you have a linux server and it's mounting a network share then chances are that network share is important you want to keep that mounted for the foreseeable future you would also mount that under m t in a subdirectory of that directory so what's the media directory for media is more for temporary storage for example you have a flash drive and you want to take a backup of the sc directory you would insert that flash drive into your linux system mount it and then you would copy your backup over to that flash drive you would mount that flash drive to a sub directory underneath slash media if you are using desktop linux you know a laptop a workstation and then you inserted a flash drive chances are it would be mounted automatically and then on your screen you would either have an icon for that flash drive or it might just appear on your screen immediately but what's going to happen if the flash drive is going to be auto mounted it's going to be auto mounted underneath slash media now the op directory is kind of a bit challenging to explain because the reason why you would use that directory kind of depends a bit on context even a bit more so than the mnt or media directories but anyway opt is a directory where you can actually store additional things one example of that that i'll give you is i had a gaming pc that was running linux and i installed a bunch of games on it i actually downloaded the games from good old games and those games actually installed to slash opt or opt so i left them all installed there and then i had all the games as a subdirectory of the opt directory so i think i had it as slash opt games and that's where i installed my games so essentially you as the user or administrator will give meaning to the opt directory and yes the linux file system standard actually has a specific definition for opt but my definition was overly simplified and then of course we have the root directory here at the beginning of the file system which i've already explained and i'm not going to go over the others because i could talk all day about the linux file system but i think the highlights that i gave you is good enough for now so what i'm going to do is go back into my home directory and there i am now what if you want to create a new directory let's explore that if you want to create a new directory you could run the mkdir command then you can give that directory a name and i'll name mine my folder and we have that new directory right there and yes like i mentioned at the beginning of the video i use the terms directory and folder interchangeably i try not to but you know what i'm only human but we do have that directory and i can create another one and now we have that one so as you can see creating a directory is very easy to do but what if i wanted to create a directory several levels down so what i'll do is i'll create a third directory and then a directory underneath that one so again mkdir i'll create third folder and i want the directory tree for this to also include a subdirectory and let's create a subdirectory underneath that one as well and it's not going to let me do that why because third folder doesn't exist and neither do the others if i was to type mkdir and then third folder just like this it would let me do it and then i can go inside that folder create subdir1 then go inside that folder and create sub-dir 2. but that's not very efficient though so i'll recall the command that failed this one right here i can add an option dash p which stands for parent that will actually allow me to create the entire directory tree it didn't error out as you can see and we have third folder we have subdur1 and inside there we have subdir2 so the dash p option is really important because if you don't want to create an entire directory tree one directory at a time you can use the dash p option to tell the system to create every directory it needs to create to satisfy what you're trying to do now let's look at the concept of removing a file i'm going to remove the file awesome file and that's actually pretty easy we could type rm short for remove and then the name of the thing that we want to remove and it let me do it and the same command that we used to remove files we can also use to remove folders as well so i'm going to remove the folder characters except i can't but wait a minute i just mentioned that you can use the same command to remove files and folders but right here it's actually failing and the reason why it's failing is because it's telling me that characters is a directory so what gives actually when we want to remove a directory we have to pass another option to the command and what i'm going to do is add the dash r option and now it's gone so you need the dash r option if you are going to remove a directory you don't need it if you're going to remove a file just keep that in mind and the dash r option stands for recursive and what that means is that if i was to go ahead and remove third folder for example which has other folders inside of it it's going to remove all of it in one shot i don't have to issue a separate rm command for each one and another command that i want to show you guys is the mv command which is short for move that command has two purposes purpose number one it allows you to rename something and purpose number two it lets you move something from one location to another so what i'm going to do is move my folder and i'm going to rename it to renamed there you go that was pretty easy i was able to use the mv command to rename an object and i could also use it to move an object as well so i will move renamed not to a different name but what i'll do is move it into second folder so now we only have that one folder and if i list the storage for that directory you can see that the renamed directory was moved into that parent directory so again the mv command short for a move can be used to rename a file or a folder or move a file or folder from one location to another navigating the linux file system is a topic that actually goes into deeper detail than what i've gone over in this video but i think what i've gone over is actually good enough for now what i recommend you do is just practice the concepts that i've gone over until you feel comfortable with those and then you can learn more advanced concepts as you go along so thank you so much for checking out this video let me know your opinions and thoughts in the comments down below make sure you hit that subscribe button because i have some awesome videos coming very soon and thanks for watching i'll see you again real soon [Music] you
Info
Channel: LearnLinuxTV
Views: 12,786
Rating: undefined out of 5
Keywords: Linux, Tutorial, Learn Linux, LearnLinuxTV, LearnLinux.tv, linux file system, file system, linux filesystem, filesystem, linux tutorial for beginners, linux command line, linux tutorial, linux commands, linux command line tutorial, linux for beginners, directory structure, linux directory structure, linux file system explained, linux file system hierarchy, linux file system structure, linux folders explained, linux directories explained, linux directories, linux folder structure
Id: BNL3qBN9pP0
Channel Id: undefined
Length: 30min 28sec (1828 seconds)
Published: Tue Mar 09 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.