let's turn this scary black screen called terminal into your superpower in the next 25 minutes you will go from help what's happening to watch this I was a junior software developer when I learned Linux commands properly and it made me feel super cool and confident so I want to help you feel that way too with this video first of all you learn the best by doing so if you follow along as I'm showing you the comms you will learn and remember this knowledge much better now the question is if you want to follow along how do you even get a Linux environment to practice commands if you have Mac or Windows laptop very easy we're going to use Docker image with Linux operating system in it with two easy steps first you're going to download Docker desktop for your operating system Windows or Mac which is super easy I actually have it for Mac so I can run it simply by double clicking on it and my Docker is up and running now you don't need any knowledge of Docker so don't worry about that you only need to install it and execute two simple commands and that's it right after that we move on completely to Linux so once your Docker is running open your terminal whether it's Windows or Mac OS built-in terminal and in the terminal we're going to download my my custom Docker image that has Linux inside plus everything else that we need for this demo so you can follow along without any set up any dist directions super easily so I will leave the link to my Custom Image below and you simply need to copy this command which basically fetches my image which is publicly available for you from internet onto your machine so you have that Linux based image locally so I'm going to execute this and once we have that image locally we're going to execute this command so basically the name of the image which is the same as here and we're going to run this as a container with this flag which will give us the Linux terminal inside that Linux container so execute and there you go no other Docker knowledge needed and with that we are inside the Linux environment and the very first command that we're going to use is to check on which operating system environment we are on so basically validate our Linux environment and to do that we have a sybol command that's called uname which basically shows you the name of the operating system that you're using and there you go we are on Linux and this command is short for Unix name and Unix is basically an underlying operating system that Linux was built on and by the way you can download our complete Linux cheat sheet that we created specifically for this video from the video description below so now that we have our Linux environment set up and ready to use let's imagine a use case for using Linux commands imagine you are a junior engineer debugging your first production issue an application is not accessible anymore it has some issues and you are on an application server now to find out what the problem is with the application and we're going to use Linux commands to solve this mysterious issue so first thing we want to do is we want to check the application logs we want to see the output of application and whether there are any errors that show exactly what the problem is so how do we find where the application logs are in the file system so first of all let's see where we are currently in the Linux file system and to do that we have a command called PWD which stands for print working directory and as you see we are in/ root directory which is root users home directory but not where our application leaves so we need to change to the application folder where the application logs are and in order to change to another directory we use CD change directory and the location of where we want to change and let's say our application logs are in /var SL log SL application and now we see in the path here that we have changed from home directory Chang to this path so now if I do PWD print workking directory there you go now how do we see what files are in this directory what is the content of this folder for that we have LS which lists all the files and other directories inside this location so let's execute and as we see we have three files for the application now let's say I want to see a little bit more information about those files for example the size of those files to see if some of them are empty or maybe error file is too large so we have lots of Errors inside as well as permissions are those files locked in production so I can access them how can we do that well for that we use a flag or additional parameter for ls- l so this will give us extended view or additional information for each file including permissions and the size of the files so now we say that there is some content inside the aor log file so we want to see what's inside to see the errors and to do that to print the contents of any file we use command called cat and we pass the file that we want to read and the name Kat actually stands for concatenate which is a fancy word basically for putting strings of text together and you can use cat command to print out contents of a file so if I execute we see that application has logged some errors now let's say our error log file is too large and too crowded so we want to specifically display any information connected to database so basically we want to filter out all the file contents and only display the lines that have a specific word or phrase in it and to do that we use what's called a pipe and pipe is basically a chain of commands in Linux so whatever this command outputs will be used as an input for the next command and the command for filtering out information based on word phrases is GP and now we can say I want to filter all the lines that have database so only show me those and let's execute and there you go you see this word highlighted as well and those are all the errors now before going forward we think it's a good idea to back up and save this information for later reference so we want to save this into a new file called database errors for future reference so instead of outputting it here in the terminal we want to save it in a separate file how can we do that we take the output of this command and we forward it to a file or we write that output into a file using this character and let's call this file database errors do text it's a text file and let's execute and now let's validate that our file was actually created by executing LS and there you go we have our database errors text file and now let's also validate that all this content has been saved in this file and it's not empty first of all we can do LS minus L and we see that part of this information is here and we can also do conat and there you go okay so now I'm thinking in case this application folder get it's cleared out on application restart or new deployment or whatever for some reason I actually want to have a backup of these database errors text file in another folder actually in my root users home directory so I want to save all the backup files there to make sure I have those so how can I copy this file and save it as a backup into a new location or generally how do I make a copy of a file well very easy we have a command CP copy and name of the file that we want to copy and the new file that we want to create let's say we don't want such a long name so let's just call it DB errors. txt but we want this file to be not in the same location but in slash root directory so how can I do that well I can simply add here the complete path to this new file so I'm saying take this file make a copy call this copied file dbr errors. text and save it in the root directory and let's execute and from here I can use again LS to list the files in the root directory without changing into root and there you go we have our DB errors right here so as you see I don't have to navigate back and forth I can execute copy LS cat and other commands so I can say slash DB errors I can use all these commands without navigating to a specific folder okay so now we have our backup the errors are safely stored away in case I needed later for troubleshooting or referencing so now I want to do a little bit further analysis I'm seeing that I have some connection refused errors and let's say my application has triy to connect to the database 100 times so I have tons of lines in my error log so I want to see how many connection errors do I have or how many times did he try to connect to the database before application crashed so let's see that first of in the database errors file I only want to see the lines that has connection refused in it so I'm going to grab or filter out and I'm going to say connection refused however when I'm using grab command to search for a phrase instead of just single word I have to enclose it in quotes so it knows this is the entire string that I'm looking for so let's execute and there you go and if I have again hundreds of such errors I can count them I can say give me a number of these connection refused errors how many times was the connection retried and to do that I'm going to pipe the output so the result of this will be piped into the next command called word count so give me a number of lines where this phrase is used let's execute and there you go we have our count okay so now we have diagnosed the problem we know that application is crushing because it cannot connect to the database on Port 5433 now this port number looks a little bit suspicious because we know that postgress database port number is 5432 so by default postgress will start on Port 5432 but the application is trying to connect on this port instead so there's something suspicious about it so now we want to see where is this port actually configured for the database so we want to find the database configuration files in the entire system how we do that we don't know where where it's located we knew the location of application log files but we don't know where the database configuration is someone else configured it so we have to find it on this entire file system well there is a command called find and we can look for a specific file name like database errors or we can look for a part of the file name so we know the database configuration will have an extension docon but we don't know what the name of the configuration file itself will be will it be POG gra.com db.com database.com we don't know how it's going to be so what we're going to do is we're going to say find a file called something do conon so this is a regular expression and it basically says find any files that have docon in the name however now we have to tell the system where do we want to look for this file do we want to look for it in the current directory which will be dot so let's see obviously there's nothing called docon in this file or we can look in the entire file system by using slash so slash represents the root file system and the file system is a tree like structure in Linux so all the files and directories basically stem from this root so we want to search this file everywhere in the entire file system let's execute okay we got quite a few con files so now we can use our familiar grap function or command to filter this large list and let's search for config files that have DB in it let's see if we find anything and there you go we have one file called db.com and it seems like it's in /c/ application so we found the DB con file now let's actually look for do we have any other configuration files for DB so let's add another star here and let's say anything that has conf it at the end because maybe there are some additional suffixes for these database configuration files let's execute and okay there is another backup file in this application folder that looks suspicious so so now let's actually switch into this folder and check our configuration there now as I said we don't have to switch to folders to execute LS and Cat and so on commands but if you have to use the file names then it's just convenient because you don't have to write the entire path you can just use the file names right so it's just a matter of convenience so now I mean we can see the contents of the DB config file but I'm actually curious to see what is the difference between db.com and db. con. backup file so someone has changed the configuration and made a backup so I want to see what's the difference what have they configured differently and for that I'm going to use a command called diff and I'm going to compare these two DB conf and by the way you can use a key called tab to autocomplete the file names for example in the directory so if I do Dot and click on tab in order fills and again there you go so this is convenient if you don't want to type out the entire file names in your commands so let's execute and see what's the difference okay so it seems like the port number to the database has changed for the application so this is a configuration file that we're passing to our application about how to connect to the database and we're saying data database is on local host on Port 5433 but we know that by default our postris database should be running on Port 5432 so the application has the wrong port and that's why it cannot connect to the running database now of course our next question is to validate is a database running and if yes is it running on this port or not so how do we check that how do we check whether a service is accessible at a specific point Port well for that there is a command called curl which basically is a command line client that can make HTP requests to services so it can make a request to a website like this so just like you access applications from browser you can access applications and services using curl or C URL so let's actually check if the database is running on Local Host which is on the same machine as we are now so let's do HTTP Local Host 5432 we assume that's the port where database is running and we're going to add an option minus I which basically says give me only the headers basically metadata without downloading the full response of the service so let's execute and there you go postgressql is actually responding on this port so now we have identified the problem we know that application is trying to connect to database on a wrong Port so that means we can fix it by specifying the correct port in the database configuration of our application so as the next step let's change it so how do we change contents of a file or how do we Ed a file in Linux well for that we have a command line text editor called vim viim and if we pass in the config file first of all let's see what happens as you see the command line text editor interface shows up and we can actually make changes here and Vim editor actually has two modes it has the edit mode where we can edit the text add new lines of configuration and so on and the navigation mode where we can get to the end of the line and so on and in order to get to the edit mode we use I but let's see what happens when we try to get into the right mode when a hit I as you see we get a warning that says changing a readon file so what's happening here well that has to do with file permissions so let's go back to the terminal and this can be a tricky part so how do we exit the Vim editor actually very easy when you know how to do it hit Escape first and as you see this here disappears and then column Q exclamation mark and this basically leaves the file without any changes without trying to save any changes so basically cancelling the edit mode and returning back to the terminal and as we see with LSL extended output we have the file permissions set here which is another important Concept in Linux and it is actually very simple the first Dash here that you see is representing whether it's a file or directory and if it's a directory it will have D standing here if it's a file it's just Dash and then we have three parts for three different users and each one of those items basically say whether the file has read permission write permission and execute permission so what we're going to do is for our root user we're going to change the permission of this file and in production let's say this config file was locked so that a program or a user doesn't accidentally overwrite the configuration it's set to read only mode so we can only read the file which we can do by conet just display the the contents but in this case we want to modify it so what can we do well we can add the right permission for the root user to this file to make root user able to write to it and to change file permissions in Linux we have a command called CH mod to change mode of this file and we're changing the permissions of dbon file and here we can provide what new permissions we want to set and we can actually set in one command the entire permissions for Linux user Linux group or any other users on the system and it's actually pretty easy if we want no permissions it's going to be 0 0 0 if we want only read permission for every of the three users it's going to be 444 all the permissions including write read execute it's going to be 777 so let's say we want read and write permission and let's actually see that and there you go every user has read permissions now everyone has all the permission including executing the file this is actually relevant for executables like bash scripts and so on let's see 666 which is read write permission for each one so it's pretty easy actually we want read and write for the root user and we can leave the rest as is with zero permissions and now let's try our Vim command again and try to edit the file and if I hit I as you see we have insert mode or edit mode and now I can delete stuff I can change stuff and so on and you can navigate with your up and down arrows in the insert mode and let's make our fix here let's delete this and set the right port and as I said in order to exit the edit mode we click on escape and in order to close the file or editor and save the changes this we use colum and instead of Q and exclamation mark we say write and quit so this will save the changes and quit the editor so now if we check dbon as you see we have made our change here and there you go we have made our change so now when we restart our application it should be able to connect to the database on the correct port and the final command to exit from the docker container back to your operating system terminal you simply type exit and there you go back in my Mech OS and if I execute unix's name here I see my Darin based operating system and that's how you can use an array of Linux commands in order to troubleshoot an issue find files on your file system navigate around make changes to the file permissions and so on and we can actually change the permission of our file back to readon to lock it down so to say like this and there you go let me know if this video was useful for you and feel free to share it with one friend or colleague that you think will benefit from it and with that thank you and see you in the next video