Quick command line commands for Windows 10

      Quick command line commands for Windows 10

      If you are not familiar with the Windows command line or if you need a quick refresh, these exercises are for you.

      Open your Windows 10 command prompt terminal.

      There are several different ways to open your command line window but, on Windows 10, my preferred way is by using the following key combination:

      Window-Key + x

      When you hold the Window-key and press x, a menu opens up on the bottom left of your screen.
      From there, select Command Prompt, or Command Prompt(Admin).
      For the most part we use the first option. Sometimes, we need to access the Admin control level to accomplish certain tasks but this option should not be the one used for comon tasks.

      Now, let's create a new folder in your users/yourname directory which is located in

      Source Code

      1. C:\Users\UserName


      Just to give you an idea, if your command line opens in system32, which is located in

      Source Code

      1. C:\Windows\System32


      you need to go up two directories which are from system32 to Windows, then from Windows to C:\.

      From this point, you need to go down to users, then userName.

      Like for example:

      Source Code

      1. C:\Users\Tony


      And the commands to accomplish this are:

      cd which stands for "change directory" and ../ which moves up one directory

      Example:

      Source Code

      1. cd..\..\users\tony


      I have just moved up from system32, then up again, then into users, and finally into tony.

      My cursor is now inside of folder tony.

      NOTE: Although Windows path uses back-slashes as separators (\) ( This was established on DOS 1 which was modeled on CP/M), modern Windows accepts both back and forward slashes as separators (this was changed on DOS 2). So, writing it one way or the other will be automatically converted to the original Windows separator style (back-slash).


      Creating a new folder or directory

      Now that we are in our userName directory, let's create a new subdirectoy called typescript-sandbox:

      Source Code

      1. md typescript-sandbox


      The command is md which stands for make directory.

      Now we have a new directory. We can verify this by using the command dir:

      Source Code

      1. dir [ENTER]


      the command dir will list all the subdirectories or folders in the current directory.

      Now, let's move the cursor into the new folder we have just created:

      Source Code

      1. cd typescript-sandbox


      We can go on and create a file inside of this directory, but let's stop for now and see how we can open Windows Explorer at the current directory:

      Source Code

      1. start.


      By typing start. (don't forget the dot on the right), the explorer will open at this location.

      You can now create a file the Windows way which is by right-clicking, selecting New Text File, and give it a name.

      Make sure you are able to see the .txt extension in your file. If you aren't, you may need to look at the command line for it, or better yet, turn on the option of seeing file extensions on Windows. Developers need to see file extensions in order to make decisions.

      Here's how:

      thewindowsclub.com/show-file-extensions-in-windows

      I think I have covered some of the essentials on Command Prompt navigation.

      To get a list of commands, type help by itself.

      To clear the screen, type cls

      Keep practicing. The command line is an important skill to develop.

      I will return with more information.


      Opening Visual Code from within the Command Line

      p.s. If you want to open you Visual Code editor from any directory you are in, just type code and press enter.

      Example (make sure you have Visual Code installed (code.visualstudio.com/download):

      Source Code

      1. code [enter]


      The above command will open Visual Code in the project you were working on the last time you used it.

      To open in a specific folder provide the name of the folder:

      Example (from inside folder typescript-sandbox):

      Source Code

      1. code ../typescript-sandbox


      The reason for ../ is to tell Visual Code to move back one directory so it can see the current directory. Otherwise it will not find it and it will create a new file with the same name as the folder you intended to target.

      Starting NOTEPAD++ from the command line

      We can also create a file directly from the command line using NOTEPAD++.

      If the file already exists, the same command will open the file so that you can edit it. If the file does not exist, it will ask you if you want to create a new file:

      Source Code

      1. start notepad++ fileName.extension


      One last thing: Sometimes we would like to send the result of a particular command to the clipboard.
      We can do this by using the following command. I'm using the command help as an example:

      Source Code

      1. help | clip


      The "pipe" symbol, followed by the option "clip" will send the "help" output to your clip board.
      You can then, open you Notepad and paste the contents into it.


      I hope it helps!
      Tony
      ---------------------------
      New eBook release: Go Exercises in Plain Language, Volume 1, Volume 2, Volume 3
      New eBook release: TypeScript in Plain Language Volume I | Volume 2 with Angular 4
      New quick read: The Factorial Recursive Function: A language agnostic explanation with samples in Go and JavaScript.
      - Please subscribe my Twitter or my Amazon profile to be notified of new releases.
      Author's profile on Amazon
      Twitter
      TonyAr

      Check your skills

      On a Windows terminal, how do you...

      Generically move from a child directory to a parent directory? (hint: 'dots')

      Show Message
      cd ../


      Moving from a parent directory to a child directory when their respective names are folder, subfolder?

      Show Message
      cd subfolder


      In a hierarchical setting such as the following, how do you move from subfolder1 to subfolder2?
      folder
      subfolder1 subfloder2


      Show Message
      cd ../subfolder2


      On the command line, how do you start your Windows Explorer from a specific folder you are in?

      Show Message
      start.
      (don't forget the dot)


      How do you start a new instance of the command line from another command line?

      Show Message
      start


      How do you make or create a new directory?

      Show Message
      md directoryName


      How do you delete a directory from its parent directory?

      Show Message
      del directoryName


      How do you list all files and directories in the current location?



      How do you list all files in the current location, but page by page?

      Show Message
      dir /p


      How would you list the contents of a sibling subfolder named sub2?

      Show Message
      dir sub2


      How would you create a file named foo.txt in the current directory?

      Show Message
      copy nul foo.txt


      How do you remove a child directory?

      Show Message
      rd directoryName


      In the current directory, how to you open a file named test.txt using Notepad?

      Show Message
      start notepad test.txt

      If the file does not exist it will ask you if you want to create a new file


      How do you clear the terminal screen?



      How would you open a project on a child directory named project1 using Visual Code?

      Show Message
      code project1


      This next one is placed here for reference only because we don't use it every day:
      How would you print the PATH environment to screen?

      Show Message

      This command will print the PATH:

      Source Code

      1. echo %PATH%

      This command will print all the environment variables:

      Source Code

      1. set

      You can always save the variables on a txt file. As an example, assuming that some file named myVariables.txt exist on the same directory, we can save the variables this way:

      Source Code

      1. set myVariables.txt



      How do you get information about your system?

      Show Message
      systeminfo


      How do you display the contents of a file (like cat in Linux)? Example file myFile.js

      Show Message
      type myFile.js


      How do you copy files, or directories with files?

      Show Message

      To copy files use copy fileName1 fileName2
      To copy directories use xcopy dir1 dir2



      This is great!!!!

      You are now ready for this next adventure:

      Show Message
      Start reading this eBook. You will enjoy it (promise!!)

      amzn.to/2g0Qm1w

      For my current and past readers, thank you!
      Technology keeps changing on us but that's OK, we programmers never get bored!!


      ---------------------------
      New eBook release: Go Exercises in Plain Language, Volume 1, Volume 2, Volume 3
      New eBook release: TypeScript in Plain Language Volume I | Volume 2 with Angular 4
      New quick read: The Factorial Recursive Function: A language agnostic explanation with samples in Go and JavaScript.
      - Please subscribe my Twitter or my Amazon profile to be notified of new releases.
      Author's profile on Amazon
      Twitter
      TonyAr

      How to change one of your computer user's password directly from the terminal

      You can change any of your computer user's password by typing the following in your Command Line Terminal:

      Source Code

      1. net user username new-password


      This comes handy when you don't remember the password of one of your user accounts.

      Example for user named Tony and a new password as t-1234:

      Source Code

      1. net user Tony t-1234


      This only works if you open your terminal as an administrator.

      There are several ways to elevate your command line terminal to admin. Windows 10 has come up with a very useful shortcut as follows:
      1. Press the Widows-Key + x

      When you press this key-combination you will see a menu on the left from which you can select Command Prompt (Admin).

      If you want to explore the net command, type net -help

      To list all the users registered in your system type net user

      Here's the official reference for more details:
      technet.microsoft.com/en-us/library/cc771865(v=ws.11).aspx
      more to come...
      ---------------------------
      New eBook release: Go Exercises in Plain Language, Volume 1, Volume 2, Volume 3
      New eBook release: TypeScript in Plain Language Volume I | Volume 2 with Angular 4
      New quick read: The Factorial Recursive Function: A language agnostic explanation with samples in Go and JavaScript.
      - Please subscribe my Twitter or my Amazon profile to be notified of new releases.
      Author's profile on Amazon
      Twitter
      TonyAr