PowerShell allows you to create directories, create files, manage the files/directories, and many directory management operations. This article provides an informative guide to changing directories in PowerShell.
How to change directory in PowerShell
PowerShell has more than 1300 cmdlets and aliases that assist in accomplishing various tasks. Alias is an alternative to the cmdlet and provides the same output as that of the parent cmdlet.
How to use the Set-Location cmdlet in PowerShell
The “Set–Location” cmdlet processes the absolute as well as the relative path. The syntax of the Set–Location cmdlet is provided below:
The –Path parameter accepts the relative or absolute path of the directory. The –PassThru parameter allows you to execute the cmdlet even if the output is empty.
The following Set–Location cmdlet allows you to change the directory using the absolute path of the directory:
The output shows that the current working directory of the PowerShell has been changed.
Let’s check the functionality of the Set-Location by using the relative path:
The current directory of PowerShell has been changed to “March 2022“.
Note: The absolute path refers to the complete path of the directory whereas the relative path is the path of the directory according to the current working directory.
How to use cd alias in PowerShell
The cd command is an alias of the Set-Location cmdlet and serves the same purpose as the parent cmdlet does. The syntax of the cd command is provided below:
Like the Set–Location cmdlet, the cd command also accepts the relative or the absolute path.
The following command allows the PowerShell to change its directory using the relative path:
The output of the command shows that the current directory of the PowerShell has been changed.
How to use chdir alias in PowerShell
The chdir is an alias of the Set–Location cmdlet which can also be used to change the current directory of the PowerShell. The syntax of the chdir is given below:
The following example makes use of the chdir alias to change the current directory of the PowerShell:
How to use the sl alias in PowerShell
The “sl” is another alias of the Set–Location cmdlet in PowerShell. The working of the “sl” command depends on the following syntax:
The command provided below makes use of the “sl” alias to change the current directory:
It is observed that the current directory has been changed to the “F:\ADNAN”.
Conclusion
In PowerShell, the current directory can be changed using the Set–location command and its aliases cd, chdir, and sl. This post demonstrates the possible methods to change the current directory in PowerShell. We have illustrated various examples to show you how Set-Location and its aliases can be used to change the current directory in the PowerShell.