So, I do want to point out that this whole cheat.sh website was brought to my attention by a viewer whose name was PseudoBase. So thank you PseudoBase. He brought this up in my tutorials on bringing weather information to your display in your shell. So again, thank you PseudoBase for bringing this website to my attention because I think it's really cool. And as always, I hope that you guys have a great day. Okay, and welcome to 2018. This video is the beginning of a series for my shell script tutorials in 2018. I've done many shell scripts in the past over the years, but this is the series I'm doing in 2018. We're going to learn a lot this year. Be sure to check out the full playlist in the link in the description or at the end of this video. Again, this will be the first.  So let's go ahead and quickly jump into the show. If you've used the shell at all, something that's very useful are manual pages. So you can type in man and the command you want to know about. So in this case, like LS is for Listing Directors, you can hit man LS and then you can go through here and look at all your options for that program, Q to get out of that. You can also do something like makedir and it will give you the instructions, the manuals for that or something like BC, which has a very long man page with a lot of stuff in here. And I always say a good man page will always have examples. But sadly, a lot of man pages don't have any examples on how the commands work. So how can you find commands? Of course, you can go and Google this command and see some examples. But there's actually a website right here called cheat.sh and it's very simple to use up here at the top. You can click this little box up here and type in the command or click the dropdown to see a full list and you can see they have lots of commands in here already with some cheat sheets. In here, I can type in LS and hit enter and it will give us some very quick examples on the LS command that you can play with or we can go makedir and you can see some examples of that or BC. And if you were to type in part of the command, so let's say I type in dir, it's going to say oh, did you mean dirs, makedir, removedir and you go oh, yeah, yeah, yeah, I wanted removedir and it will give you some examples on that. And you can even do things like sed and it will give you some examples on sed or ock. Lots of just a few examples that you can copy and paste. But again, when we're doing this on the web browser, we're working on the shell, maybe we don't have a web browser. Not a problem. Of course, if you look right here, it tells you exactly what the command is and we go back to our home directory on this website. You can see it tells you right here, show the show cheat sheet, I do curl the website and for slash command and it's going to output so in here, I can say curl cheat.sh for slash ls and it gives us the same examples or makedir or sed or even ock. And you can, of course, copy and paste these examples. So here, this last example in ock is find output separator for characters. So let's say we had this input of one, two, three with spaces, well, we can say, well, let's in between each one of those numbers, I need to send my colon. That's exactly what this command does here. We can do that. So very quick and easy to see commands, some examples for them. Examples are great. It's going to save you some googling and, you know, man pages are great to get the details. But if you just want to see how a program works, it's nice to have a command you can copy and paste and go, oh, okay, I got an idea on how this works instead of trying to go, oh, okay. So I say, set my colon, begin and then OFS and then, you know, it's easy to have an example right there. And it's a quick and easy way to do it. You can look at it in the web browser, you know, on your phone or your desktop. But again, you can do the same exact thing in your shell without leaving it. You can use curl or though I'm sure that if we were to use W get with dash Q for quiet and capital O dash for standard output, we get the same thing. Let's make that a little cleaner. There we go. So you can use W get if that's all you got. It's one of those things I love curl. I think it's a little more advanced than W get, but W gets on pretty much every Linux system, even if you're working on a router or something. It's just there because it's built into things like busy box. So it's nice to know how to both work. So there you go. I do thank you for watching. Again, this is part of a series. I hope that you stick around for us and be sure to subscribe so you don't miss the rest of the series. If you're waiting for more videos come out in this series, I still have hundreds of shell script tutorials. Just check out my website filmsbychrist.com. That's Chris Decay. There's a link in the description there. You can search through all my videos from this channel and my other channel if you enjoy my videos. Definitely think about becoming a supporter over at patreon.com forward slash malex 1000 or if you go to the support section on my website, you can also support me through PayPal. I do thank you for watching and I hope you like, share, comment, subscribe, all that stuff because it really does help. I appreciate it and I hope that you have a great day. Okay. And welcome to this second video in this series on a shell script. Now I'm going to show you a shell command here but we're going to be talking about using it for other programming languages if that makes sense. So bear with me. So last time I was telling you about a website called cheat.sh and I showed you how you could use it in the shell, do it using curl, cheat.sh and name command like make the dir and it will give you some examples of how that command could work. Well there's other options here. I'm going to show you on the website and you can bring this up without going to your web browser just by doing that it's going to tell you the same information that's on the website which is nice that they format it like that. And here we're going to look at other options and you can see that we have other languages, programming languages that you can use. So for example they have programming options for PHP or Perl or Python or C++ or examples we're going to look at today just as examples. So again we're going to use curl and then we're going to say cheat.sh and this time instead of forward slash name of the command we're going to say forward slash and a programming language so we can say C++ if we could enter, what did I do wrong here? Oh maybe the C++ part, oh of course it would help if I spelt things properly. So it seems like cheer.sh is available to anyone once that domain, anyway here we go. The programming language C++ gives you a quick description of it and it tells you it's widely used by these companies, it tells you how a compiler could work and if you execute that the output would be this and then it gives you some options here on list, learn, forward, you know, onward. So for example real quick if we wanted to search how arrays work so we could go curl cheat.sh forward slash C++ forward slash arrays and we could hit enter and there you would give you an example of how arrays work in C++ and if I was to type part of that so let's say I was just type AR it's going to give us an example, it's going to give us, okay so there's a command that says start because it has AR there in the middle, there's also arrays and then there's the learn option here. What we're going to do here is we can also go colon list and we'll list out all of the examples it has for that programming language so you can use any of these so like hello let's go ahead and give that a try. So here we'll just type in hello and it's going to give us a basic hello world for C++ example here and of course like I said you could use other programming languages so if we were to come in here and type in whoops Python it's going to give us a brief summary of Python and quickly here it shows you how to even start a web server whether you're working with Python 3 or Python 2.7 and again just like previously with C++ we can type in colon list, colon list and it will give us a list of options here that we can look at. Why did it bring up Perl stuff? Did I type something wrong there? Oh because I forgot to type Python. That's listing all the different languages there. I was going to show you that next but Python forward slash colon list and it will list just Python doesn't have a whole lot of examples here but enough to get you started again you can do hello and it will give you a basic hello world for Python. Maybe they'll add more things later. Obviously like I showed you last time there are a whole lot of commands that it has listed just for your basic shell interface but it has a few examples for different programming languages here so print hello world would be your example of course that's Python 2. Point whatever there does tell you how to install it like if you're on a Debian or Ubuntu system or if you're on Fedora or CentOS anyway so I just want to show you that the cheat.sh.sh website gives you more than just your basic shell commands and programs you can use in the shell but it gives you a few examples right now for other programming languages and again if we were to just do curl cheat.sh and colon list it will give us a list of different options so you have different shells here if you want to look at bash shell or z shell which is what I'm currently using fish you got some emack examples so these are different commands I guess you could say to bring up information on those things and then again up here we have different programming languages Lua, Perl, C++ you know this is just listing out everything that it has a list for and then you get up at the top here into commands for your shell that's pretty much it again like I showed you last time you can use W get I would use the Q for quiet so you don't see the output of W get capital O and dash will say standard output instead of putting it in a file otherwise it would put it into a file and cheat.sh forward slash and again we'll say Ock and it will give you the output for Ock or CentOS so whether you want to use curl or W get both displayed properly here in your shell of course you can always go to the website and there's a few other things that this website does but that's basically what I wanted to show you I do thank you for watching if you enjoy these videos be sure to check out my website filmsbychrist.com that's Chris the K there's a link in the description of the video there you go to the support section support me through PayPal or through patreon patreon.com forward slash melex 1000 you appreciate all support you can search through all my videos at my website from both my channels this software channel I also have a hardware channel I do thank you for watching it really does help if you like share subscribe and comment so if you do enjoy this video please do those things for me and I hope that you have a great day well welcome this is video 3 in my 2018 shell script tutorials for your Linux shell let's go ahead and look at the stack command so let's say you know if I was to list out here I've got a folder with a couple of video files in it a couple of sub folders there from Christmas Day and let's say I wanted to get information about it I could do list space dash L for list H for human readable a for all I believe because it will show hidden files as well there's no hidden files in here but I tend to that's just how I type it by default so here we go you know you got information on permissions for a file I forget what the second column is here probably file type these are probably files these are probably directories something like that don't know no that's what this is for I forget what the second column is anyway let's say I wanted to know the user or the group that owns these files I could do that and let's say just one the user of file I could list out that file let's say I want to go with this file this this Christmas morning one dot AVI AVI I could do that that lists out that file and then I could pipe that into Ock and I can then say Ock I can say print dollar sign and I want column three so one two three yep on three and there we go I can see that the owner of that file is Metal X 1000 that's me that's that's that's you know writing two commands and piping stuff and it's it's a bit longer than needed so what I could do is I could use the stack commands I can just type in stats dash C and since I want the user I can say percentage capital U here and the file name so Christmas morning AVI and right there it gives me just the user name now we could look at the man files learn more about the stack command and here we go you can see the list of options here and you can see lowercase a is the access rights in octal or capital a is access rate in human readable forms so if we were to run the same command again I can just do lowercase a and it tells me right there the permissions in octal or 644 you know sets one way but you can also do capital a and you can see that it is you know for the user it's readable or writeable for everybody else it's readable and of course you can put some of these together let's say I wanted to say the who the owner is the user that owns that file I can take percent capital U and then capital A and you I can see I get that it's the that's the user and these are the permissions here and of course I could should be able to reverse those as well and there you go actually no I did a and a didn't I there we go okay so as some examples let's look at other options we can also use it to you know get links so let's go ahead and go back in the man page here for stat and we can scroll down here and you can see a lot of options you can see you know what file type it is and what a secure Linux security contact string going down we can get just the file name if we want so a lot of the stuff that you can get with the list command but you can ask for specific parts of them without other information so that way you don't have to grep and pipe and said just to get a piece of that information just a little more efficient that way and here with the with the file name command we can use that we should be able to use that actually let's look at this capital in here quote file name with difference of symbolic link so I have a symbolic link in my WWW folder so I'm going to do is I'm gonna say stat I'm gonna say dash C and here I'm gonna say percent N and then the link is inside my home folder WWW media and I could enter and right there it tells me that this symbolic link is pointing to this directory here so that's a quick easy way to just split things up and again look at the man page because there are a lot of options in here all listed right there do do do do and again it might save you some time you know some some coding you don't need to pipe stuff which same system resources and might shorten up your commands a little bit and you can run this on a full directory so let's say we were to go back up to here I can say give me the you know the permissions and the username for all files in this directory and there you go you get both of those so that's it for this tutorial so I hope that you find that useful if you did be sure to check out the rest of my videos in this playlist and my previous playlist I've done hundreds of shell script tutorials over the years be sure to check them out on my website filmsbychrist.com that's Chris the K there's a link in the description there you can quickly search through all my videos from both my channels and while you're there check out the support section where you can support me through PayPal or Patreon I do appreciate a support also if you like my videos be sure to like share subscribe and comment that stuff helps a lot more views I get the better and I appreciate it and I hope that you have a great day hello and welcome to video four in this series of 2018 shell script tutorials I hope you've checked out my previous videos in this series as well as videos I've done over the years because I've done hundreds on shell scripts today we're gonna be looking at the make directory command MK dir we're gonna combine that with the CD command so for example I am in an empty directory right now you can see nothing in there I can say make directory my dirt and I can move into that by typing CD my dirt and you can see it's empty but moving back out of that I can remove that folder make dirt and now I'm in an empty directory again lots of the time when you make a directory the next thing you probably are going to do is move into it with CD so if you do do that all the time you might want to combine the commands okay so the first thing you want to do is come up with a name for your command and there's different ways of doing this I'm going to show you a very simple way today but in the next video I'll show you a more complicated way that does a little bit of error checking if you want if you you know if you want to call that anyway let's create a command now I was thinking originally MCD for make change directory problem is that is actually a command on my machine already MCD so man MCD you can see it may not be installed on your system it's part of the M tools which you use to work with Microsoft DOS disks which I have been working doing stuff with fat 32 partitions which I'm gonna be tutorials on in the near future and that's why I have this you may not have that command installed but it is name of the commands you may not want to use that because in the future you might install that and you go to use it and you've already overwritten it although it will still exist anyway you come up with whatever name you want and next we are going to look at replacing the MD MK dir command but today we're just going to create a new command and I'll just call it my CD okay so I'm going to call it my CD and I'm going to give parentheses so what does it mean when you have parentheses like that in a command and pretty much any program language it's a function we are creating a function here so we're going to say that we're gonna give it our little squiggly braces there and what we're gonna do is we're gonna give it two commands make dir MK dir dollar sign one and they're gonna say ampersand ampersand CD dollar sign one and do a semi-colon which I don't anything needs to be there but I like to have it there to let you know that that's the end so basically what we're doing here is we're creating a function called my CD and when you run that function it's going to run this command and this command so it's going to run make dir and CD and then the ampersand ampersand says only move into that directory if this command is successful which we'll talk about in a moment and then dollar sign one in both of these is the first string the first variable sent to the command so we'll look into that more in a second but let's just go ahead hit enter now I can type in my CD and I can type in test one and when I enter it created that directory and moved me into it in one simple command and I can move back out and I can say MCD test to and I moved into that directory and if I rest run again now I'm in another directory inside that directory so it's saving me from typing out a separate command now if I was to back out of this and I was to run this command again it's going to give me an error but still move me into that directory so if I had enter here it's gonna say that that directory already exists the file already exists because it already did make CD and it did not move me into it now depending on your scenario you may or may not want you to move into it so you're gonna create a directory and move into it it will give you this error unless you pipe it to dev know if we were to rewrite our function instead of ampersand ampersand we just do semicolon which saying is run this command and then run this command as opposed to run this command and if successful then run this command so now if I was to run this and I was typing my CD to it's gonna tell me that file that folder already exists but it's still gonna move me into it you may or may not want not want that for your thing now there might be more reasons than one this reason it could not successfully create the directory was because it existed maybe you can't create the directory because you don't have permissions to create the directory inside that directory in which case you get two fails you get a fail that you can't create it and then you get a fail that can move into it you decide what works best for you I think if the first one fails it's a good idea to stop there but again up to you now if I was to open up a new shell session so down here this is a new shell session down here like open up a new window or closing that one open up and I was typing my CD is gonna see it says that it doesn't exist it's gonna my shell because the way I have Z shell set up it's gonna suggest a change to me it because that command does not exist it create it's exist in this session up here my CD okay so the way you make that permanent you know through all your sessions is it adds your file so if you're using bash it's dot bash RC if you're using Z shell it's dot Z shell RC in your home directory I'm not gonna get into that you probably already know how to do that if not Google it and I'm also pretty sure that I've done videos on that in the past nothing I want to show you is again this dollar sign is saying use the first variable pass to us so if we were to again my CD and type in test for it create that directory move into it but if I was to type in my CD this is a folder it's not going to create a folder called this is a folder it's going to create a folder called this and ignore the rest of it so you can see I'm in a folder called this if you want it to create that entire folder you're gonna want to put quotations around that and so there we create a folder called this is a folder and moved into it you could change your function to basically use all strings pass to it that's one option if you want to do that I think that's a great idea plus you might want to add other options to that so that is a quick and simple way to make a directory and move into it in one command so now I can MCD blah blah blah and I've created it and moved into it I do thank you for watching as always I hope that you enjoyed this tutorial hope you enjoyed all my tutorials please visit my website filmsbychrist.com that's Chris the K there's a link in the description there you can search through all my videos also support me in the support section at patreon.com for sashmelx1000 or through PayPal let's check that out on my website as well and if you do like my videos and can't support financially I do appreciate a like think about subscribing and sharing definitely helps again I thank you for watching and I hope that you have a great day oh and welcome this video is part of a series be sure to check out the full playlist in the link in the description of this video as well as the end of this video also check out all my previous shell videos I've done hundreds over the years on the Linux Shell Bash Shell and other shells and in the previous video we looked at creating a command a function such as this for our shell basically we're creating our new function that makes a directory and then if successful in creating that directory we move into it so I can hit enter here and now I can say mydir123 any created directory called 123 and move me into it if I move back out and I run that same command again we get the file already exists and or that you know the directory already exists and it does not move us into it today we're going to take that a step further and what I'm going to do is I'm going to in the previous video I told you how you can put it inside your bash RC file to make it so that you can have this throughout multiple sessions first off I want to say that you can also name this function MKdir and that way you don't have to learn a new command but if you're gonna do that I would recommend doing it like so just to clarify in your code if you would do it like this so basically this is telling it specifically to make sure you're using the command makedir and not the function that we're currently in I think that if you leave that out in most cases it will probably work fine but it's good practice to put that in there but getting on to our bash RC file I've created an if then statement inside my bash RC file so dot bash RC right here I put it at the top here just to get to it quickly and I call it MKD so basically we're gonna be doing the same thing but instead of just trying to create it and if it's successful move into it we're gonna check first does that directory exist so we're saying if this directory does not exist is actually what we're checking here so we're saying the explanation mark says if this is not true check if this directory exists so if it does not exist we are going to make directory make that directory and if that's successful move into it now it can fail for multiple reasons as I said in previous video it could fail because that file or that folder file already exists or because you don't have permissions but we're checking here is does it exist so we're taking us up farther and we're actually checking does it exist if it does not create it and try to move into it that still may fail if you don't have permissions but here if the file already does exist we're gonna output a message saying that the folder already exists which you already kind of get from the maker but let's go ahead and what I'm gonna do is I'm gonna save that I'm gonna go into my bash shell and let's say make one two three which we just created so it should tell me they cannot create directory the file already exists oh that's the make dr my command was MKD one two three so you can see there's a difference mine gives you this output which is from our if then statement now why would you want to do this you're already getting that output from the maker file because in certain scenarios if you can come up with something it might be beneficial to have different checks for different problems whether it's permissions or the folder or exist you may want to which we're gonna do here in a moment just a theoretical example if that file or exist create a new folder with that name and some sort of integer at the end or some other character so a very basic example here so I'm gonna do is I'm going to go back to my bash RC file and in here I'm gonna say yeah you know the folder already exists and then I'm gonna say creating that file underscore one instead and then what I'm gonna do is I am going to call this function itself so I'm gonna say MKD dollar sign one underscore and if all goes well I can exit out of this I can go into bash again because it's in my bash RC file it doesn't automatically go into the session I'm in because the bash RC file runs me starting session so I type bash here and if I MD MKD 123 this time if I typed everything properly it says this file already exists and we are creating this instead but didn't create that so I typed something wrong it did create a folder with the underscore let's see then bash RC oh because I didn't put the one there there we go so if you go back out and now if I MKD 123 it says 123 already exists creating 123 underscore instead oh I forgot to start a new bash session whoops so let me do that real quick so that my mistake hopefully that didn't confuse you too much the changes again didn't take effect because I didn't start a new session it's my bash RC file so MKD 123 now I'm getting the results I wanted okay so it's saying that 123 already exists and creating 123 underscore instead and in which it did and it moved me into there now if I was to move back out I can run that command again MKD 123 and this time it's going to tell me oh well 123 already exists we're gonna try creating 123 underscore one instead and then it says oh 123 underscore one already exists and we're going to create 123 underscore one underscore instead you could probably come up with a better script where it actually numbers it rather than putting an underscore one each time but every time I run that command MKD 123 it will go through the cycle of checking each one because it's calling upon itself again you can make that a little bit better I'm just doing it like a quick little basic example here for you but I hope that I showed you a little bit something today so let's review the three things we went over today so we added our command to our bash RC file but not only did we add it to our bash RC file we added to it and by having an if then statement that checks where the director exists you can also have a check other things again permissions and have it do something else or permissions or give different messages whatever it gives you a little more flexibility than our code from last time which was very basic and worked but this gives you more options again if you were to want to create a function called MK DIR which is the original command that way you don't have to relearn the command it's a good practice to put command DIR in there so if I enter now and you do want to space after the curly braces here there we go so now I can say make DIR 123 and it creates so I don't have to learn a new command so it's up to you whether you want to have the MK DIR command work like this or if you want to create your own command that way they works independently of each other and again the command here is just specifying that we're using the MK DIR command and not this function so it's not calling itself so again if you left that out I think it will still work but it's good practice to have that there so that's it we learned three things putting in the bash RC file or if then statement and also the command command to make sure that we have the original command rather than the function we're calling I know I messed up once or twice in the middle there let's just go back here and just an example create another file I'll call it or folder I'll call it folder and if I move back out and try to run that again oh right MKD folder there we go so instead of creating folder which already existed it created folder underscore one again up to you in your scenario I think in most cases I would prefer if it already exists to move into that folder but that could cause problems if you do that because maybe you thought you just moved into a new directory but you moved in a directory that already exists and all of a sudden you start messing with files that are in there without realizing you start overriding stuff you might like try to cat or echo something into a file that you don't think exists and then overriding it again all your preferences is all about flexibility and doing what you need to accomplish anyway I do thank you for watching I hope you enjoy these tutorials be sure to check out the link in the description to my website filmsbychrist.com that's Chris the K there you can search through all my videos and I've got plenty of them you support section on my page and support me through either PayPal or patreon.com forward slash milix 1000 I do thank you for watching if you do like these be sure to like share subscribe and comment I hope that you have a great day and welcome to the series on shell scripts I hope you're enjoying this today we're going to be looking at how to find where certain commands are located and if you work with a shell at all you're probably familiar where the where with the where is command I could type something like where is end map and it will tell me right where the executable is and the other files that might go along with it such as the man file for the manual know what I can do is where is and I can say pwd and right here you can see that there is an executable pwd and there's a header file if you're programming and see you can use that and there's a man page as well but let's try another command where is and we'll try the read command the read command is a command that allows you to grab user input when we hit enter there it tells me where the man page for that is the files for the manual but it doesn't tell me where the executable is and that's because it is a built-in command it's built into my shell which currently right now I'm at z shell let's go ahead and type in command dash capital V in a command command you probably saw in a previous tutorial I did I briefly touched on it does a few things like telling it to run an actual executable rather than a built-in function which we did in a previous video but here with the dash capital V switch we can type in something like free and it tells me where the executable is but if we did one like read it's gonna tell me that it's built into the shell another one we can do is command capital V and we can do archive archive is actually a function that I created that is inside my z shell RC file so it will tell you whether it's a function and if I was to create an alias let's say I was to say I wanted to alias the command year to date plus percent y now anytime I type in year it's just gonna tell me what year it is but if I command dash capital V year it will tell me that year is an alias for this command so so far it will show us where an executable binary is whether it's a built-in command whether it's a function within like my RC file or if it's a alias let me go ahead and clear the screen here real quick let's create a function right here in this session let's say I wanted to create an epoch command for getting Unix time stamps and I can just do in here date plus percent s now anytime I type in epoch it's going to give me the number of seconds since 1970 so that's great now if I use command dash V and the epoch command you can see that it's gonna tell me that it is a shell function last time it told me with the archive command that it was a function that was in my RC file so I know right where it is here I know that it's a function that has been run in the current session if I was to start a new session like so and I type in epoch it's not gonna work and if I was to run this it's gonna say come on I found because it was in this session so that is the command command and you might wonder where does the command command live and you can run it on itself and you can see that it's built into the shell and as I mentioned in the previous previously in this video I'm running Z shell which is my default shell but if I was to start up bash the command command is built into bash as well and so I can use it just as I did before within bash now let's look at another command that does something similar and that would be the type command so again example type dash a instead of capital V when you type free and you can see again it does basically the same thing let me go ahead and go man oh that's not gonna work that's actually next tutorial and I can do type dash a archive and again it's gonna tell me the same thing that command command does and don't get confused again we're working a link shell if you're in Windows type is a completely different command now I haven't worked with Windows in years but back in the day and I'm pretty sure it still is type is basically like the cat command if you wanted to output a file you would type type and the name of the file and of course just like the command command I can say command type a and type in type and it tells you it's a built-in command and you can type in type a type dash a command and you can also run command on type so that is the command and type and we're gonna get a little bit more next because they are built into the shell so is that going to always work for us if we're working with different shells that's what we'll talk about in the next video or in a coming video I've got a few more things on this topic so I do hope you're enjoying these videos be sure to like share subscribe comment and visit my website filmsbychrist.com that's Chris the K there is a link in the description of the video there there you can search through all my videos from both my channels you can also support me there in the sports section there's a link to my patreon page patreon.com forward slash metalx1000 and also a PayPal link if you like to support me that way if you can't support me that way think about sharing liking comments describing all that stuff helps out a great deal I do thank you for watching hope you found this useful and I hope that you have a great day hello and welcome this is part of a series I sure hope that you check out the full playlist there should be a link in the description or at the end this video and not only this playlist but I have hundreds of shell scripts tutorials just check my website filmsbychrist.com that's Chris the K there's a link in the description so we're gonna be looking at the help command a lot of you may be familiar with the man command which is the manual command if not you really should you probably looking up stuff online don't need to for those of you who are unfamiliar most programs in the shell you can type in man and I'll give an example do end map and it will give you a manual on how to use that program and a good man page will have examples as well as I talked about in previous videos so lots of options here in the end map man page but what happens when you do something like I don't know have a command like type which we talked about in the previous video we also talked about the command command let's go ahead and type in man command oh no manual entry what if I type in man type well there is but it's not the command we're looking for these are built in functions into the shell and although there might be notes on it if you were to like man bash if you're in a bash shell which is a very long man page because there's lots of commands built in and there might be some information in there on these commands since they're built in commands but it's a long man page and yes you can search through it but there's an easier way the help command the help command so we can type in help and type and I get an error here and that's because help is not built into Z shell which I'm currently using here so but if you're running bash I can type in help and I can type in the type command and here we go I get a little help display here basically just just like a quick little man page you know some programs have this built in you type in the command and help but in this case I have the help command and I can also do command and I get the command help page so remember when you're working with different shells not everything might be there built-in functions might be different and if I command help sorry command-v help let's see what happens here it tells me it's a built it's built into the shell if I exit back out here what happens if I do command-v here I'm curious I haven't tried this yet see it's not found because it's built into bash it's not built into Z shell there might be something similar in Z shell that I'm familiar unfamiliar with so that's important to know so so now we've looked at using the type and command command to to see where programs are and we can find out which ones are built into the shell and which one are external programs and if it's built in and there's no man page sometimes there is sometimes they're not but the help command will help you but only if it's built into your shell so again if you're in bash help and the name of the command such as command and you'll get the help page so that's it for this tutorial I do hope that you're enjoying it was a quick one and yeah I love Z shell and but I also love bash and it's a shame there's no the help command isn't built in but again there might be something else I'm unaware of if there is let me know in the comments if you like my videos you like these shell script tutorials be sure to keep on watching subscribe so you don't miss any there's a full playlist in the link of the description of this video hopefully at the end of this video as well if I don't forget to put it there and again I have hundreds and hundreds of shell script videos in the past check out my website filmsbychrist.com that's Chris the K there's a link in the description there you can search through all my videos from both my channels and also think about supporting over at patreon.com forward slash my lex 1000 or with PayPal you can find that in the support section on my website if you can't support me that way it really does help if you share these videos like these videos watch these videos and I'm not gonna lie I use ad blockers but if you could turn them off while you're watching my videos that would help out too I do thanks for watching and as always I hope that you have a great day hello and welcome this video is part of a series part of a playlist check out the playlist in the links in the description of this video I hope that you're enjoying the series so far I hope you continue watching if you see a video that isn't released yet it's saying you can't access it's because it hasn't been posted yet patreon supporters get early access to video so hopefully if you're a patreon supporter you've got this as a download already early on today we're going to be looking at the pwd command the pwd command let's type that in pwd it's going to tell me where i am i'm in my home directory if i was to move directories say into my ww folder here it's pwd it'll tell me right where i'm at and if i move back out i can pwd again it'll tell me what i am what directory i am in and in previous videos we talked about the command command and the type command let's go ahead and use type this time dash a and uh then we'll type in pwd and look at this so a lot of commands it will tell you the location of that command or if it's a built-in command or if it's a function or if it's in your rc file well in this particular case it's telling me that it's built into the shell but then it's also giving me an external executable why is that well sometimes you come across some commands that are built into the shell but then there's sometimes they are also external commands and sometimes they work a little different so let's have a little bit look at this so i am in a bash shell right now and uh if the built-in bash so if i was type in as we learned in a previous video help pwd you can see here that uh it will print the name of the current working directory it has two options l and p here and the l prints the value of pwd which is a variable in your shell if it is if its name is currently is the current working directory and it tells you right here that it behaves with the dash l by default so again if i pwd it's going to tell you what directory let me move into my temp folder here though and i'm really gonna quick i'm going to make a link file dash s and i'm going to say dot test and now if i list out i can move in to this test link and you can see i'm in the same folder now if i was to type in this command the pwd command it's telling me i'm in temp test but if i was typing the full path to the external executable and hit enter you see it's telling me that i'm in temp because the l which is the default on the built in will tell you for links the external command does not do that by default so again pwd will tell me where i am including the link where the external command will tell me that i'm in temp because the link is temp is is pointing the link is linking to temp hope that makes sense but if i can i can add in that capital l and the external command works the same the difference between the two in this case is that the internal command defaults to having that dash capital l for symbolic links so uh if i was typing man pwd here we're getting a man page here but this man page is for the external command you can see right here it uses the pwd from the environment even if it contains symbolic links that's the capital l and doesn't say anywhere that it uses that by default and if we say help pwd we get the help command for the internal command which says that it does use it behaves with that so there is a difference for the most part in the same programs but that could that could mess you up if you're writing a code and you're trying to uh see when you're in a certain directory that's a symbolic link and your program's checking that and it's getting it no it's not it's not well that's because it's not using the dash shell so it is important to know which one you're using and different shells may act different again i'm in the bash shell so these are things you need to know so that you don't uh you know mess up your code uh bash is probably one of the most common shells out there that is used by default but it's not always especially if you're working on lightweight devices like like um a router or modem or even a cell phone uh so i just wanted to point that out there's other commands like this as well uh but again so reviewing this video and previous videos if we type dash a and the pwd command it's telling us that there is a built-in version of that program and an external and for the most part they're the same except for the built-in looks at symbolic links by default you can find out how to use the built-in one with help pwd you can find out how to use the external one with man pwd to see the differences which they both have the same options um it's just one default so another and that's pretty much it i do thank you for watching i hope you found this useful i hope you found this interesting and if you did be sure to like share subscribe and comment i hope you keep watching my videos i got plenty of them visit films by chris.com that's chris the k link in the description of the video you can search through my videos from both my channels there i do appreciate you watching i think about supporting we're at patreon.com there's a link in the description of the video as well as on my website under support you can support patreon or through paypal you can't support me financially think about liking share and subscribing to my channel and again as i said in the previous video i use ad blockers i completely understand i'm not holding against you but if you could occasionally turn them off while you watch my videos i would appreciate it i do thank you for watching and as always i hope that you have a great day okay real quick here this is a kind of a redo of yesterday's video while i wasn't pleased with the uh quality so i'm going to use the built-in screen recorder for android but it only records for a couple of minutes so i've got to do this quick so right now i am at a shell on my android device using connect bot which is using the default shell uh of my system which may vary from android system to android system depending on what they have this default shell setup as and if i was to run the command dash capital v command and check the command command it's going to tell me that it's built in the shell but if i was to run the type a type dash a type command it's going to give me an error saying that wence doesn't know the dash a option and if i was to run the type command without the dash a option there you'll see that it says that type is an alias for the built-in command wence dash v so the default shell on my particular phone and may vary from phone to phone but i'm just showing you that the different shells have different built-in commands it doesn't have a type command rather it's alias to a wence command which is slightly different and if i was to echo out dollar sign zero it's going to show me what my shell is or at least what it's linked to in this case system bin sh so that's the binary that we're using my default phone here now if i was to switch over to termux which is a great shell application for android phones if you do not already use it i recommend checking it out and if we were to run the same commands as before the command dash v command and the command uh that are the type dash a command you can see that the command command is a built-in shell and this one actually has the type command built in and again if we were to echo dollar sign zero it's going to tell us that our default shell is inside the termux file system and it's actually running a copy of bash and that's why type is built in anyway that was just a quick review a quick go over of yesterday's video uh in hopefully a better quality here i do thank you for watching and as always please visit filmsbychrist.com that's chris the k there's a link in the description as always i hope that you have a great day hello and welcome this video is part of a series tour check out the description of this video for a full playlist we've been looking at commands and how to find them the location of the executables and whether they're built in functions aliases and all that sort of stuff and as i've mentioned previous videos different shells may act different especially when it comes to built-in commands so here i am i'm on my android phone here's a nexus 5x and currently i'm right now we're in a program called connect bot and connect bot allows you to connect locally to yourself so right now i'm at the shell using whatever the default shell on this particular phone is and it may vary from phone to phone some use busy box some use toy box some use a standalone shell let's go ahead and uh in here in connect box issue the command command on itself and see what it says so we'll just type command command and it says that it is a built-in shell or built-in command which is what we expect but if i was to run the type uh dash a type it's it's it's new year's day and people are still saying i'll firework so if you hear that outside i apologize we're gonna go ahead and hit enter and there you can see we get an error here it's saying uh the wence or the wence c e dash doesn't doesn't know the dash a option and you're like well i didn't run the type well you'll see why that is in a moment let's go ahead and uh just try removing that dash a option from our command and running type just type and there you'll see that it says let's try to focus this a little better for that line and it says type is an alias for the built-in function wence dash v so technically the shell that we're using here doesn't have a type command it has the wence command and the one the type command is linked to that built-in alias it's an alias for the built-in command wence dash v uh so that's how that shell works and we can even look at what shell i'm running here let's again clear the screen real quick and i will now echo dollar sign zero which shows me where what shell i'm running and uh so it tells me that i'm running system slash bin slash sh again the default shell on this particular phone and actually most phones will link to that but you may have a different shell running let's go ahead and open up a different program i'm going to open up a program uh called termux and if you don't use termux you should it is a great shell uh interface on your phone so here we go we're at that and this program by default doesn't keep my screen on can i make my font bigger i'm sure i can i'm not going to mess with it right now um so that's the welcome screen for termux let's go ahead and issue our commands again so this time we'll try the command v option so command v capital v command and here as we expect it says that it's a built-in shell command and if we were to run our type dash a we'll hit enter there and it says that it's typing so this type is working as we expect it but you know we don't even need to put that dash a in there i don't know if i said that in previous videos even though uh that's the what we're told to do uh in the uh help file i think it is uh you can just type type type and usually it will tell you what you want to know as well so in this case uh type is a built-in shell sorry that gets blurry i'm at kind of an angle here it's hard for me to get straight on view and as it gets closer to the camera it gets out of focus so it's the best i can do for right now um i usually hate filming screens but sometimes you got to so let's clear this screen and again so this is in the termux shell which is not using the default system shell it's using its own shell here and this particular case if i echo zero you can see here well hopefully you can see then instead of doing system bin s h it's using data data com dat com termux files then the usr bin bash so it's basically inside this program there's this own little file operating system file system for this program and it's actually running a bash shell uh compiled for the phone so again all depends on what you're having but know the differences and know how to look it up so the command command seems to work so far in every shell i've tried type sometimes does sometimes does and sometimes it's linked to other uh commands but with one of those you should be able to figure out what you got going on and this is just one more view of that so i just wanted to share that again sorry about uh any blurriness in this video it's the best i could do uh with what i've got right now i do thank you for watching please is filmsbychrist.com that's christen k if you don't know what i'm talking about in this video be sure to check out the previous videos in this series there should be a link in the description of the video or coming up here at the end of the video thanks for watching and i hope that you have a great day today we're working with bash and looking at its histories option now as you probably know when you're writing stuff in the shells issue in commands they're being saved to a file which you can then scroll through so i can hit the up arrow here a couple times and go through different commands that i've previously typed i can hit control r and search for one like so and i can also type in history and it gives me a full list of the history with numbers because you can jump to particular commands in history based on what number they are but we're gonna be looking at disabling the history temporarily in your session so let's say you're about to run some commands maybe it's a command that's going to have a password in it you don't want it saved to your history uh what we can disable that so just to show you i'm gonna say echo one and echo two so now i can scroll up and you can see those are my last two commands using the up and down arrow keys and now i can also say set plus o that's a lowercase o history now if i say echo three and echo four and i hit up arrow you'll notice that those last two commands are not stored in there and i can echo this is a test and when i hit up arrow you'll notice that's not there the last command in the history it's disabling history and then two and that's just for this session if i was to exit out of this and start a new session let's actually let's open up a new session here we'll say bash and i'll say echo five echo six i can hit up arrow and those are there so going back up here if i wanted to re-enable history i just say set minus or dash lowercase o history and now i have to echo seven echo eight you can see that those are now in my history now again i'm working in the bash shell here my default shell my machine is usually z shell and i have tried this command in z shell and z shell does not have this option at least not like this i've tried googling it and i have found some options that don't quite work like this um if you're aware of one for z shell i didn't look that hard i'm sure i could find it but if you're aware of a shell scripts uh or a command for the z shell uh that is similar to this let me know in the comments below i do thank you for watching again i hope you find this useful again if you're there sometimes maybe you're pulling a wget command and you need to put a username and password in there or using curl or something you can run this command first and then after you issue it you can re-enable your history and you know that it isn't stored in that history there that's easier than going in and deleting it from your history file which is in your home directory uh so i do thank you for watching please visit my website filmsbychrist.com that's chris the k there's a link in the description there you can support me in the support section using paypal or through my patreon page patreon.com forward slash middle x1000 i appreciate you watching i appreciate your views your likes your shares your comments and as always i hope that you have a great day welcome this video is part of a series be sure to check out the full playlist there should be a link in the description of this video and also be a link at the end of the video i do thank you for joining me today i hope that you've watched the previous videos as well as all the hundreds of videos i have on my channel already check out my website filmsbychrist.com that's chris the k there's a link in the description so we're gonna looking at the export option when it comes to variables now uh right here we're in the shell we're working in bash and i can say um x equals 10 we'll say and i can say echo dollar sign x and of course it's going to give me 10 but occasionally you might see when people are giving instruction on stuff they might see something like this export x10 if i echo it out it works the same i think the first place i saw this at least that i remember seeing it was years ago where i was doing um ssh stuff where i was exporting and creating different displays and uh i saw them like what why is that why are they telling me to export the variable what does that mean well i'm gonna tell you what that means today so as you saw i created a variable let's create another variable i'm gonna say y equals 11 and of course i can say export dollar sign y and we get 11 but if we spawn a sub process let's say i start bash another session of bash so up here we're in bash we're in one session but we just spawn a new session down here and if i echo dollar sign y it's gonna say nothing because dollar sign because why hasn't been um created yet uh it doesn't exist yet in this session but if i exit out and then echo y you can see that it still equals 11 in the mother uh session if you want to say that uh so let me go ahead and clear the screen here so what we can do if i want to i can say export in this case we'll do z equals 12 and now that we did that i can say echo dollar sign z and it says 12 and if i start a new session of bash i can say echo dollar sign z and you can see that it has passed this variable the the processes we have spawned uh from our main process the variables are still existing in that uh sub process so that's where you might want to use export where you might be spawning different shells and terminals while you're working and you want your variables to follow into that uh but you don't want to make permanent system variables so uh i hope that was clear and i hope you understand it and hope you find it useful and maybe uh understand more because again for a while i've seen i'd seen that in tutorials and stuff and i i didn't bother looking up what it meant at first i was like okay if i'm supposed to export the variable i'll export the variable i do thank you for watching please visit filmsbychris.com that's chris of the k there is a link in the description of the video to my website films by chris and there you can search through all my videos from both my channels i have thousands enjoy them and if you like them think about subscribing liking sharing commenting and supporting maybe financially with paypal or through patreon.com forward slash metal x 1000 you can find those links at my website or in the description of the video and even a dollar a month uh you know uh i appreciate it if we can get uh you know a bunch of you to do a dollar a month that would be awesome i do thank you for watching please visit again filmsbychris.com and i hope that you have a great day hello and welcome this is a video by me chris from filmsbychris.com that's chris of the k there's a link in the description of the video and this is part of a series there's a link in the description video to the full playlist if you're going through the playlist you hit a video that has not been made public yet that's because it hasn't been published publicly yet patreon supporters get early access and downloads to all my videos so think about supporting over at patreon.com forward slash metal x 1000 i do appreciate all support and um yeah so check it out and if you're not supporting that way don't worry the video will become public be sure to subscribe and you won't miss it today we're going to be looking at creating variables in the shell and then un-setting them so this is going to be fairly simple video let's create a variable called myvar so i'm in a bash cell right now i'm going to say myvar equals this is my string and now i can echo dollar sign myvar if i could type there we go and it echoes out the string i can add that i can say echo myvar this is my string that i created and it echoes out that but still myvar still equals this is my string uh let's say for some reason you're creating a script and you want to un-set a variable at some point uh so you're using it but then you want to un-set it so that it's not being used anymore and maybe you're doing a check later on to see if that variable still exists whatever your reason for it we're going to say un-set it's that simple un-set in the name of your variable myvar in this case and it's now un-set if i try to echo out myvar you can see that it is empty it is blank there's nothing there i can go up into this it says echo myvar that i had i i created and all it's going to say is that i created because that variable no longer exists and yes this was a very short video but it could be very useful i hope that you found it useful and if so again think about supporting patreon.com forward slash malex one thousand or through paypal be sure to check out my website check out all the links in the description of the video there's plenty of them useful stuff filmsoy chris dot com chris the k as always i hope that you have a great day don't forget to share like subscribe comment all that stuff helps me out a bunch have a great day okay today we're going to be looking i'm working in uh the bash shell here on my linux machine and we're going to be looking at splitting strings uh based on spaces uh into separate variables so here's an example let's say i create a variable called myvar and i said the variable i said it to this is a test and i can of course echo out myvar and it says this is a test using the set command i can say set space dash dash and the name of my variable dollar sign myvar now if i echo dollar sign one two three and four you can see that it split each of those variables that string into each of those variables so how is this useful well let's look at some examples let's look at other ways to do something real quick so if i if config i can see my network information let's say i want my ip address here i could do something like excuse me i have config i can grab for innet and then i can pipe that into head dash and one uh just to make sure i'm up just grabbing the first uh instance of that i could also say which uh network card i want but right now i'm just going to head and one i'm going to say cut dash d and space space dash 10 so there's two spaces here so we're saying the delimiter is a space and then i want uh column 10 based on that and i get my ip address my local ip address uh which is great uh actually actually probably better because it's a little confusing having that space space there another option would be to use awk i can say awk print dollar sign two saying column two here so there we go it gets me the same result it's just a little bit clearer than so someone might not see those two spaces there if they were looking at this command okay so that's great uh and i can pipe that into a variable so if i wanted to set my ip uh to a variable called ip i can say ip equals inside quotations dollar sign inside parentheses now anytime i echo dollar sign ip i have my ip address and i can do the same if i wanted the net mask i can say i'll just do nm for net mask and that's column four and now i can echo dollar sign nm and i have my net mask and then i can do the same thing if i want my uh broadcast ip so i can say six and here let's say b well i'm gonna call bc it doesn't matter there's a command called bc on it that's that doesn't matter okay echo dollar sign bc and you can see i now have that so if we get if we if config oops fig you can see that we have cut this this ip this ip in our broadcast ip here that works but can we simplify that using what we've learned with the set command and we can very simply so what we can do is just like before we can say set dash dash and then before we gave it a string so that string can be an output of a command so basically let's look at this command we're going to do our if config command here like this uh but what we're going to do is we're just going to say head one which just gives us that line and with a set command we can now split things up based on numbers um so what i can do is just this i'll put that inside parentheses and i'll say set dash dash dollar sign parentheses so we're going to run that command which gives us this output and set's going to set variables for each of those for us now if i want my ip address i can say echo dollar sign two if i want my net mask i can say dollar sign four and if i want my broadcast i can say six so with this one command i quickly created three variables they're not well labeled variables uh but it is very simple to do now one thing you don't want to do and i i like to usually put things like this in quotation marks so it holds it together and most times that's good but if we do that now uh i believe it messes things up yeah as you can see i can only do echo one and it's all that entire string because it kind of put it all together anyway again so just the set without these quotations so set dash dash and our command there and now i can echo dollar sign two uh four and six for this example so again this one command was a bit quicker than running our three other commands which were this command this command and this command we replaced those three running those three with one command using the set command so i hope you do find that useful i hope you enjoy the tutorial i hope you enjoy all my tutorials sure check them out films by chris.com that's chris the k there's a link in the description of the video uh to my website and there you can search through all my videos from both my channels i have thousands of videos thousands of tutorials many of them on the linux shell be sure to check them out and if you enjoy them if you join my videos in general think about supporting patreon.com forward slash mail x1000 link in the description of the video you can also support me through paypal there's a link on my website to that i thank you for watching and as always i hope you share like share like share subscribe comment all that good stuff helps out a lot and i hope you have a great day okay so i just did a video the previous video on um you know uh splitting up output of a command and uh giving advice so what we did was we did this command we did uh i have config and we wanted to get the ip address so i did this i did set dash dash and then the command with the output there and then i can do echo dollar sign two to get the ip address four would have been the net mask and uh five would have been or sorry six would have been the broadcast ip um which is great very simple a lot better than doing a bunch of cutting and multiple times to get those into different values um one issue with this is that you know you're replacing these variables here which in a script or a function might already be used uh but i also right after making it i was like you know what i'm basically creating an array here which um doing it as a regular array uh you'll be able to label a little bit better so let me show you what i mean by that first of all let's change this command a little bit um so instead of this i was gripping for this really i'm it doesn't really make a difference but to make sure we get the right um device so you might have a wireless card or an ethernet card or both or more than one of each uh i really should specify which device i want and then here instead of uh i yeah i could grab that and then i don't have to worry about this head command because i don't need to grab the first one i'm getting the one from this so now i should still be able to echo dollar sign two and get the ip address so that's shortened up a little bit i didn't need that head command if i say which device i want okay but let's do this same thing but put it into a regular array so i'll just call the array ip i'll say equals and then i just put this in parentheses like this and now i can say echo and i will say dollar sign ip oops ip and i can say ip2 or ip4 obviously if i did one it would you know give us the other outputs from that the other columns uh so i mean this is a little bit longer than typing this but you kind of know what it is it's labeled properly you're not necessarily overriding uh variables that might already exist so i just wanted to bring that up i don't know why i didn't think of that earlier really uh you know you get in habits of doing stuff which you know allows you to get things done but lots of times in the past i would have done this by doing if i want the ip address i would have done you know basically uh a few cut commands and all that stuff and put that and then i'd run the whole series of commands again if i needed the net mask or the broadcast i would run multiple things so cutting down the number of processes and shorting the command by using an array either using the set command or arrays definitely a better way to go uh but i think this is a little bit clearer although the output is a few characters longer but we're actually putting into array call ip or whatever you want to call the array so that's it don't do this though uh because that's going to then put the whole command or the whole output of the command like so you won't be able to cut it up so don't put these parentheses that was the front what i did at first when i first tried this which again would tell it to ignore the spaces and say in these parentheses is one value so i hope that made sense and yeah just after doing the last video i was like oh you know what there's there's probably a better way to do that that is really obvious i should have realized a long time ago but again you kind of have like your mindset on how to do something because you've done it so long and you keep doing it that way uh so anyway thank you for watching i hope that you do enjoy my videos if you do think about subscribing liking sharing commenting all that stuff is awesome but you can also support me over at patreon.com patreon.com forward slash metalx1000 there's a link to that in the description as well as links to my website filmsbychrist.com that's chris with the k there's again a link in the description there you can search through all my videos from both my channels um and you can also find a support section there where other than just patreon there's also a paypal link if you want to support me that way i do thank you for watching as always i hope that you have a great day okay today we're going to be looking at ip tables so uh let me give you a rundown on what prompted this tutorial a couple weeks ago i was out at the park with my family and i realized i had to do something on my web server my films by chris server so i went to ssh in and nothing happened i you know typed in the ssh command and never asked for a password and just kind of sat there just hung i was like oh that's not good my server down so i went to filmsbychrist.com in the web browser and it was working fine uh so i'm like okay maybe ssh server crashed so i went to the virtual machine settings and restarted the whole machine and still same thing and then i realized oh well i had connected to some open wi-fi uh from a nearby school and apparently they must be blocking port 22 um which is just silly because it that's easy enough to get around i was actually able to get around it because uh i actually have some port forwarding going on on my pogo plug at home uh since i'm running multiple servers here it's uh so i had it running on a different port i could ssh into that and then uh pivot to my films by chris server from there but i'm going to show you how to do different port forwarding now port forwarding you're probably might become might be familiar with it especially if you do sshing to your machine at home you know in your router settings where you go in and you say okay when something comes in at this port to the router we're going to redirect to this machine that's something we're going to do today we're going to be using ip tables which is a program that uh allows you to basically do set up rules for your network instead of redirecting to another machine we're going to redirect to the same machine but uh to a different port so i am going to copy and paste this command because i actually already tried recording the tutorial twice and i kept typing things wrong i will give uh links to notes in the description and if they're not there remind me because sometimes i forget to put those there but you're going to have to be pseudo roots so we're going to say pseudo uh ip tables and we're going to do dash t whoops dash t net uh dash i we're doing some pre-routing dash p we're going to be using a tcp protocol uh dash dash d port 22222 or no 22222 uh and that can be any number you want that's within the range of ip addresses i would not use 2222 i'm just using that in the example here i would pick a higher number that is not commonly used that you can remember so um the reason i would not pick 2222 is because i've seen servers for example i used to host uh films by chris uh using host gator and their default ssh port was 22222 um so i would say that it seems like it might be commonly used so there's a good possibility that it might be blocked as well so just pick a higher number that you can remember that's uh in the range of ports which is 65 thousand something i think is the highest number anyway uh next we're going to say dash j and we're going to redirect to ports 22 so that's our first command we ran that successful everything's typed properly because i copied and pasted it rather than typing that all out um next command is another ip tables dash uh t nat dash output dash p still uh tcp pro call and then dash o l o so lo is your uh basically local network interface real quick i'm gonna control c i'm gonna do n map sorry n map local host real quick i just i should have meant to show you this before support 2222 is not open but if i if config you'll see that i have my ethernet card and then you usually have this low interface low interface is a loopback interface it's basically like a virtual interface even you had no network cards you'll have a low interface so basically it's just saying uh we're coming in on port 22 and we're going to loop back to the same machine um so again let me copy and paste so we're saying use the loopback interface to redirect port 22 to our port 2222 to port 22 now i hit enter so we've run those two commands so again this is the first command here and then this is the second command here again i'll try to put those in the notes and now if i end map local host you'll see that we have port 2222 open and you notice that it does have a name here which means or a service here that this port might be used by other servers i i don't know what ethernet ip-1 is but the fact that it has a name means that that port does have a commonly used purpose so if you're seeing that may not be the best port to use um but now i can do ssh local ah local host and that would be normal i hit that it goes to port 22 like it normally would but i can also say dash p 2222 and again it brings us to our our local host so basically just forward port 22 let's run that again uh let's run this command here but change this to port 2221 and then the second command here 2221 and now if i really quick end map local host you notice it doesn't show up again uh when you just run end map like this it's doing a quick scan of commonly used ports so it's not scanning every port but if i tell it specifically to scan port 2221 you'll see that it does tell me that it's open and that its service is normally a rockwell dash csp1 um so just to be aware that you may not see that port being used uh so that just shows that port 2222 is probably commonly used since it's in the commonly scanned ports anyway i can uh ssh local host port 2221 and connect port 2222 or just port 22 so all of them are actually going to port 22 so now if port 22 is blocked it doesn't matter because i am reconnecting to it through a different port that's just forwarding to the other port clear as mud again i will put those commands in the link in the description but for now i will also just for your convenience put them up on the screen here right there i will leave them up there while i talk here for a moment i just want to say thank you for watching i hope you found this video useful i hope that you enjoy my videos if you do think about visiting films by chris.com that's chris the k there's a link in the description uh check that out there you can search through all my videos there's also a link there to um search through my scripts and this is actually in my notes so when you go there it will bring you to a little website uh that will load up a list of my scripts it's actually very poorly written it actually loads up every single script from my pay spin account um into the html of the page and then it searches through that so it's a little slow as i add more i really should um have it search the database and then just output what you're searching but anyway uh so filmsbychris.com you can search through my videos you can search through all my scripts if i do forget to put this uh code a link to this in the link in the description of this video remind me but it is in my um notes so filmsbychris.com click on scripts and that should bring you to a little search where you can search through all my notes and just type in ip tables i don't have very many uh notes on ip table so you should be able to find it there um think about supporting patreon.com port slash metal x1000 uh there's a link to that in the description of this video also on my website under the support section you know support me through paypal i do want to thank you for watching and as always i hope that you have a great day okay today we're going to be looking at aliases and how to um you know bypass them when need be so here's an example if i type ls it's going to list out the files in the directory there's three uh files in the current directory now let's say i like this command and i use it often ls-lha that's um the list of view human readable and all i believe i hit that it's going to give me a view like this which gives me a lot more information on the files let's say i want to use that as my default ls command i can say alias ls equals and inside single quotes or double quotes i can say ls and give it those uh functions now if i type ls here uh you can see it runs that command so uh well i have different settings in my bash rc file so i lost my color settings in there but that's that's not uh what we're talking about today anyway so now anytime i type ls it's going to run that full command but let's say i have that set but now i do want it to just display the filenames yeah do i i can unset the um the variable by user the aliases by saying unalias ls and now if i ls you can see it's back to the default ls command uh let's go ahead and re-enable it first off unaliasing now it's like now if i want that back i have to re-aliase again unaliasing also only unaliases it for the current session so if i start a new session of bash and that aliases in my bash rc file it's going to be re-enabled in the next session all i want is to be able to quickly you know i always want to be like this but occasionally i want it to be the old way well there's a few different ways to do that first way so ls does this but if i wanted to use the default ls command i can give it the full path to the ls command uh well i for i can use the command command which we've talked about in the past i can say command uh command i can say command ls and it's going to run the actual ls command not our alias uh and then the ls command can also be that's a little bit long what is what i'm trying to say i'm sorry i'm losing my train of thought typing the commands a little bit long so there's other ways you can also put the ls command in double quotes or single quotes see again if i do it without those it prints it the long list another option that's probably the easiest is to backslash ls another way would be to type out the full path the command so like it'd be uh usr bin ls which i don't actually think yeah uh where is ls so let's do bin ls so i could do that i could type out if i knew where the the command was and it's either going to be usr bin ls or bin ls it's going to be in one of those folders could could be somewhere else as well um so again i have this alias set i just want to temporary just this one time bypass it i can backslash it i can put it in quotations single or double i can type command ls or i can type out the full path to the command so it avoids the alias and again you can unalias it which turns it off for this entire session uh but if it's in your bash rc file or or z shell rc file or whatever it's going to be re-enabled the next time you start a new shell so keep those in mind thought you might find that useful because alias are great but sometimes you want to go back to the default command and i personally think just the backslash would be the easiest so thank you for watching i hope that you enjoyed this video please visit my website filmsbychrist.com that's chris the k there's a link in the description of the video uh please check out my website search through all my videos find what you're looking for i have thousands of videos you can also support me patreon.com slash metal x1000 or through paypal sports section on my website there so i thank you for watching please visit filmsbychrist.com and i hope that you have a great day hello i hope you're enjoying this series on linux shell commands and um be sure to check out the full playlist there should be a link in the description of the video um and today we're going to be looking at logging uh messages to log files on the system now let's say you're you're writing a script and it's going to try to do some things and obviously if there is an error fails you're going to have some output to the screen to the user but you may want to log it to a log file for the system there are different log files for different things um just to have a record of that so that you know the sysadmin can go back and and look over it and see where these errors are happening so uh let's go ahead and just quickly look at the end of one of these log files so i'm going to use the tail command which uh will show us last 10 lines by default of a file i'm going to say var log messages that's one of the log files and you do have to have permission to do this so i'm going to sudo and you can see the last 10 lines of that log file it tells you uh you know it was on the local host uh you know the the user that uh create generated this message this was a network manager um and then like down here was an example i did which uh so my name is metal x1000 and then the error message so let's go ahead and see how you log to that file obviously you you shouldn't just write directly to it by uh you know redirecting your output into it there's actually a command called logger and you can do something like logger this is an error obviously you'd want to give a little more information than that we do that and now if we run that same tail command you can see that there was a on the date and time the local host this user this is an error was dumped into that file so let's go ahead and uh work that into a command so let's say we wanted to copy and i'll make up a file here that doesn't exist i'll say my file dot log and we want to copy that to our temp folder because we're backing up to our temp folder whatever you know obviously you don't want to back things up to your temp folder because it's temporary anyway let's call it backup dot log um we'll give it a number blah blah blah okay so we do that and it's going to fail obviously because that file doesn't exist what we can do is one way of doing this is checking is doing the double pipe as i've shown in previous tutorials that means if the last command fails do this and we can say echo fail and now not only do we get the copy command error but we also get our little fail error which obviously you want to give a little more information than that um but we can also use our our log command so i can say logger um with two g's and i'll hit error and it's been logged to the system file so now if i was to go up and tail that out again you can see that that message get there and obviously again you'd want to give more information than just a fail um but if you want to do both and again there's different ways to do this you can do a full if then statement if you're writing this in a script as a one-liner i can put this in parentheses and add two commands in here so i can say echo fail which you're getting the output from the copy command in this case anyway but fail i'll say logger failed to copy file and we'll say this file and then i'll hit enter so in a script it would try copying this file to here and it's saying well if it fails give our fail output which shows right here on the screen but also log it and so now we can say uh tail that and you can see right down here that it has been logged it gives the date and time what user was running it obviously on local host and the error message and you want to be as descriptive as possible without getting too long and that's just one log file if i was to uh list out here i can list out all the farlog files you can see there's a bunch of them blah blah blah for different things and there's different ways to write to them so go ahead and look through the man file for logger so you just man blogger should bring it up and it will give you different um options while running this command so you know look through that learn a bit but very simple just do that base command logs to the uh the messages log and um that's pretty much it it's not a bad idea if your script is doing anything of importance and you want to be able to troubleshoot later to write to the system log file so you have an ongoing record of that and the system takes care of those depending on your system setup every so often it's going to tar those files to compress them down a tar and g zip them i believe uh is the compression used and uh it will keep them for so long so you can go back quite a ways on the system unlike uh the default on like a window system once you if it logs anything once you restart lots of times that stuff is gone um luckily a linux system by default backs up and it's just little text file text files are compressed over time so you can definitely troubleshoot quite a while back so i do as always thank you for watching please visit my website filmsbychrist.com that's chris of the k there's a link in the description of the video uh there you can look through all my videos you can also go to my scripts my notes and search through all my scripts and notes um you can also support me in the support section either through paypal or patreon.com for it slash mill x 1000 i'm actually looking into some other options i heard about something new the other day uh but i don't want to put it up there i don't start using it until i know more about it um but different ways to support me and uh if you can't support me financially think about liking sharing subscribing and commenting those thumbs up's help a lot shares definitely the more views i get the better i do thank you for watching and as always i hope that you have a great day hello and welcome i hope that you're enjoying the series so far on shell commands for your linux shell and today we're going to be looking at a program called i notify wait uh which allows you to monitor directories and files for modifications and things such as that and just them being accessed so let's go ahead and the command uh you would have to install so you can sudo apt install i notify let's see i notify tools on debbie and base system i don't know if it might be called something different i already have it installed so i don't need to do that right now so i'm gonna say i notify wait and i'm gonna say dash m and i'm gonna look at a directory that does not exist at this moment so i'm gonna hit that it's gonna tell me it doesn't exist so let's go ahead and and create that real quick so i'm just going to say make dirt so that now exists i can now run this command and it's sitting there and it's watching and it's waiting and i'm gonna open up another shell here and i'm going to echo test into a file inside that directory so i'll say echo test into temp examples my file or move file my file and as you can see up here it tells you that the in this directory there was a file created it was my file it was opened it was modified and it was written to and closed so uh that's monitoring a directory for any changes made to it let's go ahead i'm gonna come up here i'm going to uh kill this command the control c and now i'm going to point it at that file and say my file and hit enter so now it's monitoring that file in particular so i can come back down here and i can run that you know i can keep adding to that actually i'm adding to it i'm replacing it each time uh and uh let's see i'm just curious if i do this yeah it just it just doesn't say whether it's added to it just tells you that it was open modified written to and closed so uh but that's just monitoring that one file if i add to a different file you see nothing happens up there because it's only monitoring that one file but if i come back up here and run the original command which is looking at the directory now whether i'm adding to file two or the first file it will log it up there or not log it but let you know it will monitor it and tell you so let's go ahead and change that a little bit right here it's telling you whether it's open closed so let's go ahead and monitor this file again let's see my file what happens if i go vim and i say to my file up there it tells you you know what was happened to it and i can say write file and it tells you know attributes change so it's telling you a lot of stuff here but let's say we only want to be monitored um notified of the modifications not when it was open not when it was closed just when it was modified so let's go ahead and kill this command and we're going to run that same command again uh but instead of just m we're going to do dash q and dash e now uh and then type modified here modify so now you can see it's only telling me when it's been modified so i saved it there i can write to it this way and it's only telling me when it's been modified not that it's been open or closed or written to just that it's been modified in some way um and there's a lot of options again look through the man pages for more information on that let's go ahead and send a system message out and there's different ways you can you send notify i guess there's no not not notify send uh there's notify dash osd i've seen people use uh to get gooey pop-ups but another command that we can look at is the wall command a wall command i can say wall test and it sends that command to every shell running it broadcast it says who sent it so if you're on system with multiple people and everyone's using a shell you can run that and it just sends that message says who sent it and when and from where uh to the entire system so that's great you're working in another shell you may not be looking at this but you'll get a notification up on the screen when things change so let's go ahead and modify our little command up here so we can incorporate that into it so we're gonna run the same command we ran looking for when it's been modified and this is my first thought when i was testing this out read i'll say line and i'll say do and i'll say wall dollar sign l and done now if i come down here and let me open up two shells here uh like that so you'll see that it goes to both shells so i'm going to modify that file boom so all my shells got a message saying that was modified so that that's awesome i get that now there are certain times when the if you're modifying the file in a certain way where you're going to get uh multiple outputs so here i got the one wall command here to it but sometimes there's certain modifications that it seems to modify it twice and um you get double messages i don't necessarily want double messages uh so especially if you're using one of the gooey applications you'll get multiple boxes up on the screen so go ahead and kill this if you look in the man file uh the man file actually has a slight variation on what i did so basically it's the same command uh but what we're gonna do is we're going to be sure to say redirect dev null here uh semicolon and we're gonna say uh instead of doing while here we're actually going to write it so we're gonna say while this command is running and we don't need the dash m here according to them so we're gonna say q e modify this file dump into while and then we're going to say wall and um we're just going to say here file modified go ahead and hit enter and in this particular scenario it should work the same way here it's instead of saying the output from the command it's actually saying our message so that's a slight variation there and again in the example i'm giving it's not doing two messages but uh when i did test it in certain ways you'd get double messages especially with the uh notify send it was popping up multiple boxes this variation on the command works a little bit better um so that's again in the man file uh and there you can you know if you're concerned maybe you think uh you know there's some reason why i'm on that you want no when it's been updated maybe you're checking a mail file although there's better ways to check a mail file using proc mail and stuff um but you're waiting for a file to be modified and you want to be notified when it happens you can use the wall command but i uh notify wait and the again the package on at least debium based system is i notify wait dash tools go ahead install that and now you can monitor when files and folders are modified and send yourself messages i mean here i'm doing a broadcast out to everybody using the wall command uh we again can do gooey where you get the little box with something like notify send but you also have it send you emails or texts from your computer so that you know you're not at your computer your phone will get a message uh wherever you're at i do thank you for watching uh again this video is part of series for check out the full playlist uh as always uh you can go to my website filmsbychrist.com that's chris the k there's a link in the description there you can go through all my videos search through them very conveniently you can also um support me there in the support section we got the patreon.com forward slash metal x 1000 also have paypal link there any support even a dollar a month is much appreciated and uh also there you can also look at my script section which we're bringing to my notes and you can search through right now i have almost 600 uh paste bin notes but i made a searchable application there so you can search through them all it's not the best written search application because it dumps a lot of data could have been written much better but you can search through there and uh as always i thank you for watching and i hope that you have a great day this video is part of a series be sure to check out the full playlist and the link in the description of this video i hope you're enjoying these shell script tutorials and uh we're looking at some shell commands today today we're going to be looking at the gang the p id uh the process id of a running process a running program uh this is useful to in many ways to kill a process but if you need to get a process id there's two different ways the way that i normally do it which is not the best way i think a lot of people do this is they use the ps command so if i if i ps it will give me a list of running programs but that's just for this current session if i do uh a ux is usually the way i run it which gives me for all users and all that stuff and then of course i can grep that if i want to say let's say my shell is z shell so i probably have a few of those running right there let's clear the screen run that again so this is all the z shell or at least all the commands uh running with the word z shell there which is not necessarily all z shell uh processes for example i'm getting the grep command that i just ran because it has the word z shell so that's not the best not the cleanest way to do it well you can also use the ps command uh if you look in the man page dash capital z is case sensitive and i type zsh it's going to give us a nice little clean these are you know uh processes here's the id is the tty for them and uh time i don't know a little bit but uh cmd is the command so that's nice clean we're not going to have to worry about that grep command blah blah blah and that's fine and if we want to there's probably a ps command to get just the process id uh but i would pipe this into just doing what i know dollar sign one meaning the first column and that kind of works we got the process id here but we also have this p id which we could remove with ochre grep blah blah blah but we're piping again unnecessarily we don't need to do that again there might be a ps command to get this process id uh look through the man page but i'm going to show you uh two other ways that actually uh work a little bit better uh one and this is the simplest remember is p id of so it will give you the p id of and i can say z shell here and it just gives us all the process id for the z shell processes another one is p grep uh and i said to say p grep z shell and it basically gives you the same output not necessarily the same or it looks like reversed um one gives you in a column format one gives you you know with spaces either or you can loop through those uh and kill them all if you want although the kill all command would also work um but you can go through those and if you need the p id uh of a process whether it's running one or more those are probably the two cleanest ways i know of is p id of and p grep uh so check those out and i know a lot of there's a lot of different variations of grep out there e grep p grep blah blah blah and a lot of those processes depending on the version of grep you have uh well those process a lot of those functions depending on what version of grep you have might be built into regular grep already and in fact that might be an alias for a regular grep i don't even look into that i just know p grep z shell but actually p id of is the one that i've started using recently because it's just um easy to remember if i just need the p id obviously um doing uh my original command if i'm uh let's see psa ux grep z shell uh gives me a little more information if i'm looking for a particular one i go and i can copy and paste but if i just want to script it out to grab the p id of all the processes or you know maybe find the latest one i can use one of those other commands and it's a bit cleaner uh one of the most powerful things in a in a shell is the ability to pipe the output of one command into another command but at the same time you should limit doing that as much as you can because you're running processes you don't necessarily need if one command can do it so i do thank you for watching as always be sure to check out my website filmsbychrist.com that's chris at the k there's a link in the description there you can search through all my scripts my notes under the uh script section it's either called scripts or notes on my website i need to check i think it's called scripts it'll bring you to my notes uh which is basically uh anytime i create a script or write notes for myself i put them in paste bin and paste bin is great but there's no right clean way to search through it so every day i have a cron job a mic uh server that pulls down the latest uh posts that i've done puts them into a database and then this interface on my website will search through it in a very sloppy way i actually have every script load into the html of the page and then i use javascript to to sort through that and really i should be sorting it with the database not loading everything in the page because it makes a little slow it's not that slow on a desktop computer on a phone right now there's almost 600 scripts in there and again it searches through all of the words on that and your device doing that so on an older phone it might take three to five seconds for it to filter through everything so i really need to rewrite that to do everything on the server side just as a you know just that's but i'm actually holding off on that because i'm actually starting to use gist more so i'm posting all my scripts to paste bin and gist so i'll probably look into seeing if there's an api for gist um and start using that said because that definitely is a little bit nicer because it does revisions and stuff like that if you've never used it if you've used git it's like git but for you know projects there's one or two files rather than a full blown project anyway i'm babbling now but looking through that i have lots of great notes there i've put it there i built for myself but i'm sharing it with you guys i go there all the time you know i know i know how to do something i don't remember how to do it i can type in the keywords and it will narrow down my my scripts and i can look and see how to do something about having to google it and then read through articles it's just that my notes are very short or code there check it out also check out the support section on my page you can go to patreon.com for ssmlx1000 or my paypal account again all that films like chris.com go ahead check that out support is great be sure to like share subscribe comment all that fun stuff i appreciate you watching i also appreciate you sharing so other people can watch too be considerate of other people let them know how great my videos are as always i hope that you have a great day