How do I move between folders in a command-line session without losing my place?
Quick answer
Before moving, save or note your starting location. In Bash, use pwd to check it, cd path/to/folder to move, and cd "$start_dir" to return if you first saved it with start_dir=$PWD. In PowerShell, use Get-Location, Set-Location path\to\folder, and return with Set-Location $startLocation after saving $startLocation = Get-Location. Paths depend on your prepared practice folder. [S1][S2]
The question, the details, the next step.
A practical checklist
Use a prepared practice folder and note its expected subfolder names.
Identify whether the session is Bash or PowerShell.
Save the starting location before navigating.
After each move, run
pwdin Bash orGet-Locationin PowerShell.Return to the saved location and check it once more.
A few more useful answers
Can I use the same command in Bash and PowerShell?
Not always. Use cd and pwd for the Bash steps shown here; use Set-Location and Get-Location for the PowerShell steps.
Will the example show the same full path on my computer?
No. The displayed path depends on where your practice folder is located. Check that the ending folder name matches the step you intended.
What if I did not save my starting location?
Stop rather than guessing. Inspect the current location and identify the correct starting path before continuing; the return-variable examples only work if you saved that location first.
Sources
References used for this guide.
- [S1] Bash Reference Manual: Bourne Shell Builtins gnu.org · Checked
- [S2] Managing current location in PowerShell learn.microsoft.com · Checked
