Gadgetory


All Cool Mind-blowing Gadgets You Love in One Place

Must Know - Command Prompt & Batch Files

2016-05-04
hey everyone I am joined by Patrick stone to talk about command prompt so we're billing this as things everyone should know about command prompt basically useful commands and items that will get you through troubleshooting or looking like a hacker on public television or something like that so bring us in here what's give us the first item everyone should know about command prompt so when you're using command prompt it's not the absolute most powerful command-line interface which I guess says to to me it's it's usable anybody can learn it if they want to right it's not like Linux they're not exactly you know the Linux has its terminal right and there are similarities but not exactly the same and the but the one thing like if anybody wants to learn about command prompt the key to all of this the magical awesomeness is forward slash question mark almost every command you want to learn about if you just type in the command and then a space and then forward slash question mark it will give you a help menu on how that command works right it gives the flags mm-hmm what they do and generally not a good idea to just pull commands off the internet forums and paste them because you don't know what someone's trying to do to your computer if it's Linux the equivalent would be like shamone 777 your entire system which for those who don't know would basically open up public read/write access to every everything oh you don't want a scenario like that so it slash question mark I'll answer that stuff Linux equivalent would be like a man as a man manual vigil yep and for Windows command prompt what we're focusing on so the more useful items would probably be on the troubleshooting side I've always used sort of scan OS fix OS mmm fix big jar rather a fixmbr yep stuff like that yeah so there's a boot command you type in boot re see one word mm-hmm rec and then you can do the slash question mark and you'll see those commands so fixmbr fixes the Master Boot Record yeah but now be careful with that one right there if you try to go and do bootrec from your basic command prompt it's not going to work you got to be in the so basically like you got to be booting from a flash drive with the windows install discs all right what does repair mode command prompt what you're getting that there and I should say this too if you're in startup repair and you click on the command prompt option there you can use bootrec from there right yeah but if you're just in like you you go to your Start menu and windows is working fine and you do CMD and run as administrator or whatever and type in bootrec it's gonna be like what's that yeah exactly and that's for your own safety really yes so that's that's one of the things and Windows nowadays is generally smart enough which I hesitate to use that word with Windows but generally intelligent enough to tell you something's wrong with the MBR something's wrong with OS detection and you can go into that pre boot environment and there's a lot of it right around the appropriate command if you know how to do the command prompt last question bar and scan OS is an important one because if you have multiple OS installs on your drive and it's not detecting one that you know is there you can do scan it fix boot racks and then scan OS and it'll tell you although Isis they detect yeah when you do scan LS it's gonna give you a list of the operating systems that it finds and then it's like which one would you like to add back to the boot configuration database and it's like one two three and you just choose the number also useful if your boot up is telling you that there's multiple os's and you only want one and then you remove the ones that you don't want there mmm ideally uninstall them correctly but what's another command Ron tell me with neither one so another really useful one is check disk chkdsk and then again force last question marks you can figure out what the flags are flags options whatever you want to call them and the one you're gonna find yourself using most often is /r which is a repair now you you can't do this online meaning you can't be using your computer and do the repair so what it will do if you do check this last hour gotta be running as administrator by the way which again type in CMD in the Start menu you'll see a CMD pop up there right-click choose run as administrator and then do chkdsk and then /r and it's going be like hey we couldn't do this right now would you like us to schedule this to do nice time you reboot and then what it's gonna do is it's gonna scan the sectors on your hard drive and this is going to look for bad sectors now if there's information in there that's that's valuable and they can recover that information is going to grab it out of there and then it's gonna mark that sector as hey don't use a sector anymore and this makes a drive that is running really slow oftentimes improve because what's happening is the drives trying to read over and over and over again on this one bad sector and you're like why is this read taking forever and the answer is because the sector is going bad and then when you run check disk it's like hey I'm not using that sector anymore it's like my hard drives back to normal again and you can also check the hard drive health to with smart attributes so you don't know if there's a problem that you feel like there might be go look for any smart SMA RT attribute reader mmm and then it'll tell you if it thinks sectors are bad or things like that yeah use that first pin pin commands are good excellent one yup so that's a really simple one you can use it right now from your desktop please type in P ing space and then give it a domain name or IP address yep so if you have like google.com it's almost always up pinging Google com that will basically give you a response time how long it takes a packet information to get there and back yep that's right yep and then and then that'll tell you is the website down is my system down whatever my network yeah you're basically checking for network connectivity it is your computer connected and right and is it connected to whatever site or IP address is trying to get to if you want some fun trivia look up pain of death it's not really something you can do anymore but it's it's kind of cool information sort of like an early DDoS yeah exactly exactly basically pinging with really large packets is another really good networking one IP config this one is just an information command that's not true you can do stuff with it too meaning that you can release and renew your IP address right so the the process of getting an IP address is called DHCP it's a protocol and you you've got a DHCP server sitting so on your network whether you know it or not most of the time it's your router so like let's say you got like a Linksys box or a net gearbox or something that it's got a software DHCP server running on it so when your computer joins the network or when your phone hops on the network it sends out a request and it's like hey is there any DHCP server out there and the DHCP server replies back with the message and says yes I am the computer's like kind of have an IP address than DHCP servers like sure here's one and so you get this IP address and if you do IP config release the address you've been given is then released from your computer and if you do an IP config we're new it does that DHCP for DHCP process again and then you get another IP address or most of the time the same IP address back yeah useful if there's like IP conflict on your internal network or something like that absolutely right and then traceroute that's another networking one that's useful so I have used this a lot on the server admin side managing the GN server where if I call support and say hey there's a really slow response from my server they'll have me run a traceroute and the point of that is to look at all the different points that your packet of data hits along the way to its its destination it goes hops in the network environments and so all it's doing is it saying okay when I'm at the server what's the default gateway for the server and it shows that hopped that d-ball gateway and then it goes to the next one next one next one all the way until you get to your destination now some of the time the information is blocked right by some of those devices that are in that hop count but a lot of the time when you're just going across the public Internet it's just all there and you can see everything yeah it's just trace RT and you can do the slash question mark to get information on that but one fun thing to look at that a lot of people maybe don't know is your ISP Time Warner 80 any other evil empire you can think of Comcast comes to mind when I say that the ISP hello when you do a trace route for different servers you'll actually see jumping through all these hops and so you're actually you're not getting the direct connections on the server you're going through potentially a dozen yeah different hops and right and they might even be owned by different ISPs or different servers whatever they all talk to each other exactly right so kind of an interesting information there any other networking stuff before I move on to batch files well so if you're interested in paying and you're interested in traceroute there's kind of an in-between it's called path pane that is not what I know that yeah so so put path thing it kind of does a little bit of both so the the penguin gives you a little bit more information about how long things taking that kind of stuff and the trace routes a little more like you know here's your pathway so path thing is kind of like ml between the two so yeah a little bit of both worlds very cool and then batch files are sort of so good yeah they work with mannheim so we use these a lot for testing and test automation specifically so just as an example something that will often do is run these benchmarks as you all know for 1080p 1440 4k and we'll have ultra medium whatever so there's times like 20 folders we create for every single video card so we just sit there and click all the time and then type and type yes yes I can click 20 times per video card no how do we do so you can do a batch file which is you just do a notepad open up notepad and you can type in in this instance mkdir make directory mkdir space and then the name of the file you quotations if it's gonna be with spaces in there but you do that and then that'll actually just when you run the batch file dot bat you rename it to dot bat instead of txt on the batch file it'll create that folder yes so in this specific example if you want to create 20 folders and even you can get more advanced and nest them in each other your kid and you click it once and I just yeah and it's all there for you so so in other words rather than you know programming this or testers are typing this every time you write the program once and you create a parent folder for each different graphics card and then you've run the program in each parent folder right and it's and I say program very loosely it's just like we said a batch file and in the end a batch file is mostly just command prompt commands inside of a text document that gets renamed you delete the extension dot txt you add the extension dat right and in Windows you'll have to tell it to allow you to do yeah you have to show extensions exactly right so you can do that in the folder options and you go to options but one of the other useful things here things like time out time out when I such a good one yes we've all is even right pause is very good for debugging mm-hmm so if you create a batch file that's supposed to do something cool and it sort just opens and closes now one method I used to use was you try and screenshot it really fast and see what the error said but it turns out you can just type in pause after certain lines and you'll figure out which one it's it's dying on okay so that's pause timeout what does time I do so timeout you do a slash T after that's the option for timeout and it's really having options required and syntax and then after the slash T you put in a number of seconds right and so what that does is let's say that you you wanted to see the output but you didn't needed to stop the program so you would say all right do this command then wait five seconds so I can read the output and then just keep going everybody saw the timeout command works right so we use that and testing again where you have like a timeout 1:20 so two-minute timeout and then it'll launch or kill a program if so it's another good example if you want to start a program in a batch file or even just from command prompts because they're really all the same yep command you just type in start space and then the path to the file or the exe or whatever and it enter it'll execute so we'll use that for programs games would ever start DRT dot exe and start dirt rally there you go and it launches it and then you can set a timeout separately and that will you know to wait whatever amount of time before executing the next command which is maybe to kill it yeah so there's taskkill mm-hmm that's a good one yeah so task list and task of kinda go ahead and hand task list like the this one I've used for again we're talking about things that anybody can use and that can be useful if you've ever been infected with a virus before maybe you lose control of your GUI but you can open a command prompt you can use task list and it shows you basically the same thing you see in the processes view of the task manager and the cool thing is you can add an option to that task list slash SBC and it even shows you what's in each service host and so you can find you know this random thing that's like one two three four I'm not a liar Exe right and so you get this thing and you find the process ID for it or the image name for it which is just the name of the file and then you do task skill and you have to specify /am for image name and type the XE name or /p a PID and type in the process ID for it so these are really good for troubleshooting or like he was saying just ending a program right so two good ones yeah so you have trouble ending a program can't get the command proper task manager you could certainly do it that way there's plenty of other commands too but batch files are really one of the most fun for me to work with I will probably do a full video on that in the future but with batch files again just think of any sort of repetitive tasks or if you want to be playfully malicious you can even do things like a shutdown batch file yeah so that's that's a good one where or a command prompt that creates infinite command prompts oh I forgot about that so it's a good one yeah you just you start over and over yeah so that's that's an endless loop of command prompt yeah and then you put it little donut father don't do this go to put up a startup folder and anyone who died never works again I already doesn't know how to get the safer it is screwed so that's the one fun thing to do shutdown as fun as it is to be malicious is actually functionally useful as well yeah so I've done this where for example if I'm downloading a patch for a game okay like pick an MMO right yeah you download a patch forever and you may want to go to sleep don't want to leave it drawing power so you can set a down command from command prompt and give it a timer yep absolutely yeah you know it'll be done in four hours you tell it shut down in four hours yeah and you can you shut down command also those restarts - and one of the cool things is if you had some reason to restart one of the one of the restart flags you can do is a restart and reopen applications that were previously running so it's kind of a cool thing yeah yeah and the other base there is one more that I think everybody should know so one of the things if you're going to use command prompt is you have to understand file structure you really do but before you go messing around with all this stuff please please please go get like a brief primer and file structure right when somebody says the route of a drive yeah you didn't know what that means or when they say a folder inside of a folder or when they use the word directory you know what these words mean and one of the best commands for navigating around the command prompt is CD right thank you change directory yeah or if you don't know what your current directory is because you've changed your prompt with the prompt command CD will show your current directory so it has two functions right and then dir will show you everything in the directory you're in and that's a really small tree the memory tree will look more slightly more graphical format can do that as well right but dirt and CD are fantastic yeah yeah yeah Darry that's that's one that I've used regularly for going into safe mode with man prompt so if there's a virus issue I'll always go safe mode with command rounds and I'm thinking of older Windows operating systems here where you have no interface yeah right and in that situation it was good because you're really not loading any risk elements that could contain the virus and you might want to navigate to your avast or a Norton folder or whatever I guess I guess you would navigate to the Norton folder to remove it and never use it again because it's terrible and when you're there you can type in dir find the Exe name start it and that will start your antivirus or removal or whatever yeah yeah so lots of really good uses for command prompt if it's not something you've learned just go check it out and try some of the things we've mentioned here lots of cool automatic guides there for them and you know it can do a little networking it can do a little bit of file management it can do automation for you if you know how to use that if you're going to use the batch files so command prompt totally something that as I guess you could call yourself a power user right you you should know how to do speaking of there is a PowerShell extension so if there's something commands command prompt can't do em hmm there's a powershell for that yeah so if you are at all interested in learning about servers and doing Network administration you definitely learn PowerShell PowerShell is basically the backend of Windows Server you can run Windows Server with absolutely no GUI and PowerShell can do everything that you ever wanted it to do right so there you have it a previous video that we did together have you've seen it was all about batteries that you'd ever not want to know now you have command prompts but this stuff is actually really cool and fun to use and functionally useful and it's impressive - as I said public television viewers so as always the links in the description below for more information postal video has a patreon link if you want to help us out directly thank you for watching we'll see you all next time
We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites.