Hi all,
Today I will explain the steps to change the default directory for Windows command prompt and Windows PowerShell.
The default directory for both the command prompt and PowerShell is the "system32" folder of the OS installed directory (By default: "C:\windows\system32").
Day in - Day out, we will open the terminals (command prompt / PowerShell) and navigate the source directory. It sometimes irritates and wastes lots of time.
I have come across this situation and want to avoid re-entry the change directory command.
Environment,
I use the command prompt and PowerShell, which are pinned to the taskbar of Windows.
Change default directory of Windows Command Prompt
- Right-click on the taskbar pinned Command Prompt icon
- Right-click on the "Command Prompt" menu
- Select the "Properties" item
- Under the "Shortcut" tab, you will find the "Start in:" label
- In the respective text box, enter the path you want to navigate by default.
- For example, "C:\Projects".
Change default directory of Windows PowerShell
- Open the PowerShell with administrator privileges
- Create a profile by using the following steps
- New-item -type file -force $Profile
- This will create a file "Microsoft.PowerShell_profile.ps1" in the current user documents PowerShell folder.
- Syntax
- C:\Users\<UserName>\Documents\WindowsPowerShell
- Example
- C:\Users\PSR\Documents\WindowsPowerShell
- Edit file
- notepad.exe $Profile
- Change the default directory
- Syntax
- Set-Location <Directory Path>
- Example
- Set-Location C:\Projects
- Clear-Host # To clear the PowerShell screen
- Save and close the file
- In the PowerShell window, enter the following command to change the profile
- . $Profile
- It immediately changes from the current directory to the updated default directory.
- Close the PowerShell and try to open the PowerShell again to see the change in the directory.
Hope the above information is helpful to you reduce the change directories in day-to-day life.
Send me your valuable feedback to psrdotcom@gmail.com.
No comments:
Post a Comment