Linux Workshop Part 3 | How To Navigate Linux Filesystem

What's up Sons it's blindroid with son Of a tech once again and welcome to Linux Workshop part three today we're Going to be talking about the file System navigation file system navigation Is probably the most important skill you Can learn when working with Linux Because it will help you understand Where you are at any given time and you Will need to understand this when you Are working with different applications Within Linux and editing configuration Files and so on and making sure that you Know where you're replacing those files And how they are accessed from different Scripts Etc so first things first we Need to distinguish the difference Between an absolute path and a relative Path the definition of an absolute path Is an absolute path on Linux computer is Like a full address for a specific file Or folder just like how you need a full Address to know where to send a letter a Computer needs a full address to know Where to find a file or folder an Absolute path starts with the root Folder which is the very topmost folder On the computer and then it gives the Complete list of all the other folders You need to go through to get to the File or folder you want so let's go Ahead and take a look at our Linux Console here and give you guys an Example starting out always I like to

I show You how To Make Huge Profits In A Short Time With Cryptos! I show You how To Make Huge Profits In A Short Time With Cryptos! Welcome to the Future of Money

Make sure that you know that you are Working within the correct machine so You can type host name and we are Confirmed that we are on our tutorial Machine now the next thing we want to do Is confirm that we are using the correct User and we'll do that with a who am I Command and you can see we're logged in As the user sub so we know we're on the Right machine and we're logged in with The correct account so we aren't making Any mistakes or changes to a system that We do not intend to make changes to from Here we're going to check the working Directory that we are starting in with The command PWD which we covered Previously and you can see we are Currently at root if we want to navigate To our home folder we can do a change Directory tilde and then run PWD again And you'll see we're in our home Directory at any given time you are Going to use the command change Directory in forward slash to go to the Top most directory within any Linux file System and you can see that we can Confirm that by doing PWD and we are in The forward slash directory now if we Want to type an entire absolute path and Navigate to the sun's home folder we Will do change directory slash home and Then slash sun and if we had another Folder in within that directory we would Just continue the full address so we're

Going to do slash home slash sun and We'll do a PWD and we can see that we're In the sun directory let's go ahead and Talk about the relative path so you can See the distinguishment A relative path on a Linux computer is Like giving directions to a friend to Find a toy at your house instead of Giving the full address of your house You can just tell them where to find the Toy by saying things like go in the Front door then go up the stairs then Turn left then go into my room and it's On the Shelf a relative path on a Computer works the same way it tells the Computer where to find a file or folder By giving the direction starting from Where you are right now and that's why It's important to understand the PWD Command right so you can tell where You're working from at that time And this is instead of starting from the Very top which is always signified from The forward slash It makes it easier for you to navigate Around the computer because you don't Have to remember the full address of Everything so let's go ahead and move Back over to the desktop and we'll show You how to do this I'm going to do a Clear command that clears the console We're going to do a PWD command and you Can see that we're working from the Slash home slash Sun directory now if we

Do a change directory and dot dot that Will bring us up to the home directory And you can see here if we do PWD that We're in the home directory not Nissan Directory we can utilize an LL command To list the directories that are within The home directory and you can see here That we have sun and we have test these Are the two users that are on this Machine so from here we can change Directory into the sun folder by just Typing in change directory sun and Pressing enter at this point we can run The PWD command and you can see that we Moved from home into the sun directory However if we went to the root directory And then we look at all the folders if We try to change directory into the sun Folder well there's no sun folder so we Won't actually be able to go into there And this is why we would need an Absolute path because we need to know Where to go so at this point we can go Ahead and do the absolute path of change Directory and we know that the sun Folder is in home so we'll do slash home And then slash Sun Let me go ahead and clear the screen so You can see this So we go change directory slash Home Sun and that would be an absolute path This is extremely important when Scripting because depending on where the

Script is it will basically need to Either have a full path or of course you Can do the relative path so absolute Path though in general when doing any Kind of scripting is what I would Definitely recommend however if you're Just navigating around within the system In the command line it can be useful to Utilize relative paths to go ahead and Get to those a little bit quicker and This could be because you also don't Know where the what folders are in there Right so if we do a PWD command you can See that we're in the home slash Sun Directory well maybe we're looking for a Folder but we don't really know what It's called so we'll do the LL command And we can see here that we have a test Folder it's actually highlighted in blue So if we wanted to change directory into The test folder from here we could do Change directory and test and at this Point if we do an LL we'll see that we Are in here with all of our created Files and if we do a clear and then a PWD you'll see here that we're in the Test directory which is an undersun and Under home So hopefully that gives you an idea of What the difference is between a Relative path is and an absolute path Moving on from there let's talk about Different commands you can utilize the Man command man in Linux is short for

Manual it is a command that you can use To read the manual pages for different Programs and tools on your Linux Computer manual pages are like Instructions or a user guide for a Program that tells you what the program Does how to use it and what the Different options and commands are when You type man followed by the name of a Program the manual page for that program Will be displayed on that screen for you To read so let's go ahead and go back to Our Linux console here and we are going To use the ls command to for this Demonstration so we'll type in man and Then LS and you can see here that Essentially really lists out all of the Different options for LS this is Important because you can see here that We have we can do the down arrow key to Browse through this we have all these Different options and these options that We type in for the ls command will give Us different option or different Outcomes right for example Dash H with Dash L and dash s print file sizes like 1K 234 M and 2 gig instead of just doing The entire bytes and this is going to be Easier for people to read for the human Readable you can at any time press the Q Button to quit out of it so now we're Going to talk about the change directory Command or the CD command the CD command In Linux is used to change the current

Directory the current directory is like The folder that you are currently inside Of on your computer when you open a Terminal window you are automatically in A specific folder and you can use the Change directory command to move around To different folders on your computer Going back of course we talked about This a little bit before but we're going To run the PWD command to see the Current working directory that we are in And then to move to the utmost directory We are going to do change directory Slash we can do a PWD command to confirm That we're in the topmost directory and Then from here here's an interesting Shortcut and that's tilde For the logged in user you would want to Check the logged in user first with who Am I And you'll see that we're Sun if we want To move into Sun's home directory think Of it like a file library in Windows we Are just going to do the shortcut change Directory and tilde at this point if we Press enter and then PWD what you'll Notice is that we are in the home Directory now to move up one folder in The system we can use another shortcut For change directory which is change Directory space dot dot what this will Do is move us up One Directory we'll do The PWD and we you can see that we went From Sun to the home directory and this

Is just basic commands for change Directory to move a folder using an Absolute path you must type in the full Path of the desired location we talked About this earlier for example to move Into the home directory of the currently Logged in user with absolute path you Would type the command once again change Directory slash home Slash sun and at that point we can do The PWD command to confirm that we are In the sun directory to navigate to a Directory from the current directory via A relative path we can type the command Change directory or CD change directory Name for example like we showed earlier I'll do a clear we'll do LL and you can See that we have that test directory Once again we would just do change Directory and test this would be an Example of a relative path and we could Press enter and then PWD to confirm that We are in the test directory relative Path does not use the forward slash in Front of the path name if you are moving To a directory that is held within Another directory you will use the Command change directory directory name 1 and directory name two for this Example what we could do is go up one Directory With changed directory dot dot And then do change directory Sun actually we need to go up one more

Into home for this example And you can see if we do a PWD we're in Home Because if we do an LL real quick you Can see that the the sun directory is Within here because the sun directories Here we can still utilize a relative Path and continue it on so for example We can do change directory sun and then Forward slash and then the test at this Point we can do PWD and confirm that We're back in the test directory Moving on from there let's talk about The ls command you've been seeing me Utilize it a little bit let's talk about It in further detail the ls command in Linux is used to list the files and Folders in a directory when you run the Ls command it will show you the names of All the files and folders that are Inside the current directory To find all the options for the command We can once again like we showed you Guys earlier use the man space LS Command and then we will have the full List of all of our different options to Exit this once again you press the Q Button to quit The most common options used with ls is The L for long list format and then t For the newest first that will basically List out the newest file you created First and R for reverse order which will Basically reverse it so that at the

Bottom of the list will be your newest File this would look like something like This we would basically do LS and then The dash LTR press enter and you can see Here that by time of creation it lists It in order you can see the latest file Is the lsdef and this can be extremely Important when you are trying to find Maybe the last file that was created Because you forgot the name of it and You need to re-edit it that sort of Thing all right so let's talk about the WC command the WC command in Linux is Short for word count it is a command That you can use to count the number of Lines words and characters in a text File in addition it will count the Number of files in the directory when Using the pipe command and so we're Going to be talking a little bit about Piping which will take the results of One command and then further basically Disseminate that for additional Information to find all of the options For the WC command we're going to go Back into our Console and do man and then WC at this Point you can see that we have all of Our different options for the WC command And you can once again press the Q Button to quit out of that to display The amount of words in a text file we Can use the command Wc-w and then the file name so the file

Name in this case is going to be this Lsdef file that we've created and to see How many words are in this particular Text file what we are going to do is Type Wc-w and then a quick way if it's a long File name that you don't want to type Out you can right click or highlight it And then right click within putty and it Will display it another option is you Can start to type out the file and press Tab and that is your auto complete a Couple quick tips there at this point we Press enter and you'll see that we have Essentially 40 word words in this Particular file to find the amount of Files and directories in a directory you Will need to use a cut pipe command in This case it will look like this let me Clear the screen for you and it will be LS which is going to once again if we Press enter it's going to list all of The files in this directory right And then we want to pipe it to WC so we Can find out how many files are in here So we're going to use the pipe command Which is the little straight line above Your enter button and then we're going To do WC for word count and dash L Dash L is saying count the lines because LS Is going to basically give us a bunch of Lines and then We are going to press the enter button And you can see that it says seven so we

Can verify this by doing LS Dash LTR and You can see here that we have one two Three four five six and seven lines so Now we know essentially we have seven Lines that could be directories and Files that's how we're going to find out How many directories or files are within This directory this can actually get a Little complicated if we're talking About things that have so many lines That you can't read them and this is Where more and less commands actually Come into play the more command in Linux Is used to display the contents of a Text file one page at a time when you Run the more command followed by the Name of a text file it will show you the First page of the file and then pause You can then press the spacebar to see The next page or cue to quit and exit Because if it won't show all the files In your console and it lists them all Out you aren't going to be able to see All the files unless you utilize a more Or less command The last command in this case is just More Co is just the more command in Reverse but allows for you to go up and Down with the page up and page down Buttons on the keyboard so let's go Ahead and go back into our system and Look at some examples so change Directory to the utmost directory with The change directory forward slash

Command and you will be in here so to View the contents of the directory Page By Page we're going to type in the Command LS Dash l t r and then we're Going to pipe the more command in and Press enter and you can see here now at The bottom of the screen let me move Myself out so you guys can see this Because it fills up the entire deal it's Going to pause here on the list and Basically give us all of the all of the Files that are in here to go further Down we're just going to press the space Button and we get page two to view the Contents of the directory in reverse Order Page by page with the ability to Move up and down we're going to use the Next command less this example is going To be Ls-ltr and then we're going to pipe the Less command here And at this point we can do the page Down but we got whoops maybe there was Something up there that I didn't see We're going to do the page up and we can Go back up at any time here we can press The Q button to quit out of the less so Let's go ahead and talk about the grep Command the grep command in Linux is Used to search for a specific text Pattern in a file or group of files the Grep or grep stands for Global regular Expression print it searches for a Specific string of characters called a

Regular expression within a file or a Group of files and Returns the lines That contain that expression so for Example here what we're going to do is We're going to find user details in the Password file to do this we're going to Utilize the command cat cat's going to Grab everything from this directory so We're going to do cat slash Etc password Or p-a-s-swd Now if we just do this it's going to List everything and we really are Looking for a specific user right so we Want to actually clear this out and once Again you can always press up on the Keyboard to go through your previous Commands if you need to quickly get There and we are going to want to use The pipe to add grep and then we're Going to look for the user Sun so we're Going to do basically Cat Etc password and then gret for Sun and Here we'll get the line within that Directory or that file that gives us all Of the information for the sun user and We can go over all of what all this Means later on but essentially it's Going to tell us kind of what shell the Sun user is using we can change that We'll talk about that in a later Deal and we'll talk about all of the Definitions here as well in a later Video so another use case that we can

Utilize the grep command for is quickly Finding open ports for a specific Service this could be SSH or in the case Of building a node it could be for the Node on the system and we need to know The port that we need to connect to Right so to see what port the SSH Service is using we're going to use the Example here we'll have to use a pseudo Command to give us elevated Privileges And then we're going to do the l-soft Command lsof and then we're going to Utilize all of these switches once again You can use the man lsof command if you Want to find all of the different Options we're going to do Dash I lower Cache we're going to do Dash I lower Case then we're going to do Dash p Uppercase Dash and lowercase and then We're going to pipe and look for sshd Which is basically the SSH Daemon and at This point we're going to go ahead and Press enter it's going to ask us for our Password for the pseudo privileges Type that in press enter I messed it up There we go and you'll see that this Command gives us all of the sshd ports That are running you can see here that It's on Port 22. So now we know that we can connect Via the IP on Port 22 you can see here It lists the entire IP if you need to Connect from another machine and then You're good to go

So that's it that's going to be Linux Workshop part 3 navigating the file System if you found this video helpful Be sure to hit the like comment and Subscribe down below and I will see you Next Tuesday

You May Also Like