Becoming a computer guru simply means doing what your mates can not do on the computer system and not just doing it, but doing it very fast. The only way you could work very fast on a computer is by using command prompt or any other kind of command line program. You can delete a whole file in no time and no one except the smart people like you would know how you did it. Most people shy away from command prompt because they have the impression that commnad prompt is very hard and requires someone to have Jimmy Neutron's brain in order to use it. But, in this post, I am telling you that command prompt isn't as hard as it looks, and to clear my point on that we are going to be running some cammands using a windows built-in tool known as Powershell.
Note: Powershell can be found on computers with Microsoft Windows 7 and higher.
To start, go to start menu, in the search box, type "Powershell" and Windows Powershell will be filtered out. Right click on it and click Pin To Taskbar so that you can always start it up from the Taskbar without having to search for it every time you want to use it.
Now click to open it, When it is opened, you are ready to start using it for wonders. You should see a screen similar to this:
Now the commands we are going to be treating in this post are Get-Location and Set-Location which are the basic folder navigating commands. When navigating folder systems in Windows Explorer, you usually have a specific working location - namely, the current open folder. Items in the current folder can be manipulated easily by clicking them. For command-line interfaces such as Cmd.exe on Windows and Terminal on Linux and other OS, when you are in the same folder as a particular file, you can access it by specifying a relatively short name, rather than needing to specify the entire path to the file. The current directory is called the working directory.
Windows PowerShell uses the noun Location to refer to the working directory, and implements a family of cmdlets to examine and manipulate your location.
Getting Your Current Location (Get-Location)
To determine the path of your current directory location, enter the Get-Location command:
PS> Get-Location
Path
----
C:\Documents and Settings\PowerUser
Note: The Get-Location cmdlet is similar to the pwd command in the BASH shell. The Set-Location cmdlet is similar to the cd command in Cmd.exe.
Setting Your Current Location (Set-Location)
The Get-Location command is used with the Set-Location command. The Set-Location command allows you to specify your current directory location.
PS> Set-Location -Path C:\Windows
After you enter the command, you will notice that you do not receive any direct feedback about the effect of the command. Most Windows PowerShell commands that perform an action produce little or no output because the output is not always useful. To verify that a successful directory change has occurred when you enter the Set-Location command, include the -PassThru parameter when you enter the Set-Location command:
PS> Set-Location -Path C:\Windows -PassThru
Path
----
C:\WINDOWS
The -PassThru parameter can be used with many Set commands in Windows PowerShell to return information about the result in cases in which there is no default output.
You can specify paths relative to your current location in the same way as you would in most UNIX and Windows command shells. In standard notation for relative paths, a period (.)represents your current folder, and a doubled period (..) represents the parent directory of your current location.
For example, if you are in the C:\Windows folder, a period (.)represents C:\Windows and double periods (..) represent C:. You can change from your current location to the root of the C: drive by typing:
PS> Set-Location -Path .. -PassThru
Path
----
C:\
The same technique works on Windows PowerShell drives that are not file system drives, such as HKLM:. You can set your location to the HKLM\Software key in the registry by typing:
PS> Set-Location -Path HKLM:\SOFTWARE -PassThru
Path
----
HKLM:\SOFTWARE
You can then change the directory location to the parent directory, which is the root of the Windows PowerShell HKLM: drive, by using a relative path:
PS> Set-Location -Path .. -PassThru
Path
----
HKLM:\
You can type Set-Location or use any of the built-in Windows PowerShell aliases for Set-Location (cd, chdir, sl). For example:
cd -Path C:\Windows
chdir -Path .. -PassThru
sl -Path HKLM:\SOFTWARE -PassThru
Saving and Recalling Recent Locations (Push-Location and Pop-Location)
When changing locations, it is helpful to keep track of where you have been and to be able to return to your previous location. The Push-Location cmdlet in Windows PowerShell creates an ordered history (a "stack") of directory paths where you have been, and you can step back through the history of directory paths by using the complementary Pop-Location cmdlet.
For example, Windows PowerShell typically starts in the user's home directory.
PS> Get-Location
Path
----
C:\Documents and Settings\PowerUser
Note: The word stack has a special meaning in many programming settings, including .NET Framework. Like a physical stack of items, the last item you put onto the stack is the first item that you can pull off the stack. Adding an item to a stack is colloquially known as "pushing" the item onto the stack. Pulling an item off the stack is colloquially known as "popping" the item off the stack.
To push the current location onto the stack, and then move to the Local Settings folder, type:
PS> Push-Location -Path "Local Settings"
You can then push the Local Settings location onto the stack and and move to the Temp folder by typing:
PS> Push-Location -Path Temp
You can verify that you changed directories by entering the Get-Location command:
PS> Get-Location
Path
----
C:\Documents and Settings\PowerUser\Local Settings\Temp
You can then pop back into the most recently visited directory by entering the Pop-Location command, and verify the change by entering the Get-Location command:
PS> Pop-Location
PS> Get-Location
Path
----
C:\Documents and Settings\me\Local Settings
Just as with the Set-Location cmdlet, you can include the -PassThru parameter when you enter the Pop-Location cmdlet to display the directory that you entered:
PS> Pop-Location -PassThru
Path
----
C:\Documents and Settings\PowerUser
You can also use the Location cmdlets with network paths. If you have a server named FS01 with a share named Public, you can change your location by typing
Set-Location \\FS01\Public
or
Push-Location \\FS01\Public
You can use the Push-Location and Set-Location commands to change the location to any available drive. For example, if you have a local CD-ROM drive with drive letter D that contains a data CD, you can change the location to the CDdrive by entering the Set-Location D: command.
If the drive is empty, you will get the following error message:
PS> Set-Location D:
Set-Location : Cannot find path 'D:\' because it does not exist.
When you are using a command-line interface, it is not convenient to use Windows Explorer to examine the available physical drives. Also, Windows Explorer would not show you the of the Windows PowerShell drives. Windows PowerShell provides a set of commands for manipulating Windows PowerShell drives, and we will talk more about this in the posts to come.
Enjoy your new guru skill and thanks for reading.
Note: Powershell can be found on computers with Microsoft Windows 7 and higher.
To start, go to start menu, in the search box, type "Powershell" and Windows Powershell will be filtered out. Right click on it and click Pin To Taskbar so that you can always start it up from the Taskbar without having to search for it every time you want to use it.
Now click to open it, When it is opened, you are ready to start using it for wonders. You should see a screen similar to this:
Now the commands we are going to be treating in this post are Get-Location and Set-Location which are the basic folder navigating commands. When navigating folder systems in Windows Explorer, you usually have a specific working location - namely, the current open folder. Items in the current folder can be manipulated easily by clicking them. For command-line interfaces such as Cmd.exe on Windows and Terminal on Linux and other OS, when you are in the same folder as a particular file, you can access it by specifying a relatively short name, rather than needing to specify the entire path to the file. The current directory is called the working directory.
Windows PowerShell uses the noun Location to refer to the working directory, and implements a family of cmdlets to examine and manipulate your location.
Getting Your Current Location (Get-Location)
To determine the path of your current directory location, enter the Get-Location command:
PS> Get-Location
Path
----
C:\Documents and Settings\PowerUser
Note: The Get-Location cmdlet is similar to the pwd command in the BASH shell. The Set-Location cmdlet is similar to the cd command in Cmd.exe.
Setting Your Current Location (Set-Location)
The Get-Location command is used with the Set-Location command. The Set-Location command allows you to specify your current directory location.
PS> Set-Location -Path C:\Windows
After you enter the command, you will notice that you do not receive any direct feedback about the effect of the command. Most Windows PowerShell commands that perform an action produce little or no output because the output is not always useful. To verify that a successful directory change has occurred when you enter the Set-Location command, include the -PassThru parameter when you enter the Set-Location command:
PS> Set-Location -Path C:\Windows -PassThru
Path
----
C:\WINDOWS
The -PassThru parameter can be used with many Set commands in Windows PowerShell to return information about the result in cases in which there is no default output.
You can specify paths relative to your current location in the same way as you would in most UNIX and Windows command shells. In standard notation for relative paths, a period (.)represents your current folder, and a doubled period (..) represents the parent directory of your current location.
For example, if you are in the C:\Windows folder, a period (.)represents C:\Windows and double periods (..) represent C:. You can change from your current location to the root of the C: drive by typing:
PS> Set-Location -Path .. -PassThru
Path
----
C:\
The same technique works on Windows PowerShell drives that are not file system drives, such as HKLM:. You can set your location to the HKLM\Software key in the registry by typing:
PS> Set-Location -Path HKLM:\SOFTWARE -PassThru
Path
----
HKLM:\SOFTWARE
You can then change the directory location to the parent directory, which is the root of the Windows PowerShell HKLM: drive, by using a relative path:
PS> Set-Location -Path .. -PassThru
Path
----
HKLM:\
You can type Set-Location or use any of the built-in Windows PowerShell aliases for Set-Location (cd, chdir, sl). For example:
cd -Path C:\Windows
chdir -Path .. -PassThru
sl -Path HKLM:\SOFTWARE -PassThru
Saving and Recalling Recent Locations (Push-Location and Pop-Location)
When changing locations, it is helpful to keep track of where you have been and to be able to return to your previous location. The Push-Location cmdlet in Windows PowerShell creates an ordered history (a "stack") of directory paths where you have been, and you can step back through the history of directory paths by using the complementary Pop-Location cmdlet.
For example, Windows PowerShell typically starts in the user's home directory.
PS> Get-Location
Path
----
C:\Documents and Settings\PowerUser
Note: The word stack has a special meaning in many programming settings, including .NET Framework. Like a physical stack of items, the last item you put onto the stack is the first item that you can pull off the stack. Adding an item to a stack is colloquially known as "pushing" the item onto the stack. Pulling an item off the stack is colloquially known as "popping" the item off the stack.
To push the current location onto the stack, and then move to the Local Settings folder, type:
PS> Push-Location -Path "Local Settings"
You can then push the Local Settings location onto the stack and and move to the Temp folder by typing:
PS> Push-Location -Path Temp
You can verify that you changed directories by entering the Get-Location command:
PS> Get-Location
Path
----
C:\Documents and Settings\PowerUser\Local Settings\Temp
You can then pop back into the most recently visited directory by entering the Pop-Location command, and verify the change by entering the Get-Location command:
PS> Pop-Location
PS> Get-Location
Path
----
C:\Documents and Settings\me\Local Settings
Just as with the Set-Location cmdlet, you can include the -PassThru parameter when you enter the Pop-Location cmdlet to display the directory that you entered:
PS> Pop-Location -PassThru
Path
----
C:\Documents and Settings\PowerUser
You can also use the Location cmdlets with network paths. If you have a server named FS01 with a share named Public, you can change your location by typing
Set-Location \\FS01\Public
or
Push-Location \\FS01\Public
You can use the Push-Location and Set-Location commands to change the location to any available drive. For example, if you have a local CD-ROM drive with drive letter D that contains a data CD, you can change the location to the CDdrive by entering the Set-Location D: command.
If the drive is empty, you will get the following error message:
PS> Set-Location D:
Set-Location : Cannot find path 'D:\' because it does not exist.
When you are using a command-line interface, it is not convenient to use Windows Explorer to examine the available physical drives. Also, Windows Explorer would not show you the of the Windows PowerShell drives. Windows PowerShell provides a set of commands for manipulating Windows PowerShell drives, and we will talk more about this in the posts to come.
Enjoy your new guru skill and thanks for reading.
Comments
Post a Comment