Как перейти в папку в powershell
Итак, с командой pwd мы уже познакомились в первом уроке. А сейчас изучим еще несколько команд для оболочки командной строки Windows PowerShell.
Открываем Windows PowerShell и вводим следующую команду: cd desktop
Эта команда говорит компьютеру: перейди в каталог (в папку) desktop. То есть в «Рабочий стол» (по-русски).
Чтобы убедиться, что мы находимся в папке «Рабочий стол», нам надо ввести уже известную нам команду pwd :
Результат ввода этой команды:
Теперь вводим команду mkdir 1 . Эта команда говорит компьютеру: создай в текущем каталоге папку (каталог) с именем 1.
Результат будет такой:
| Mode | LastWriteTime | Length | Name |
| d—- | 12.03.2019 12:23 | 1 |
PS С:\Users\Boris1985\desktop> _
То есть компьютер создал в папке desktop новую папку 1 и сообщил об этом нам.
Чтобы убедиться, что так все и произошло, сверните все окна и посмотрите на рабочем столе – появилась папка 1 или нет. Должна появиться!
Теперь давайте создадим несколько вложенных одна в другую папок.
Посмотрите на Рабочем столе внутри папки 1 – есть ли в ней вложенные папки 2, 3 и 4?
Теперь давайте перейдем сразу в 4-ю папку.
Проверьте с помощью команды pwd , где вы находитесь.
А теперь перейдем на один уровень вверх. Для этого введем команду cd..
И опять проверьте каталог, где вы сейчас находитесь – командой pwd . Вы сейчас должны находиться папке 3. Точно также пройдите выше по папкам — до папки desktop. Для этого вводим:
Домашнее задание
- напечатайте в Windows PowerShell по 10 раз команды: cd, pwd, cd.. и mkdir
- проверьте — появились ли на рабочем столе созданные вами папки?
В следующем уроке мы научимся в окне Windows PowerShell создавать новый файл, а также удалять и просматривать содержимое папки — перейти в следующий урок.
- Вы здесь:
- Главная />
- Python 2.7 с нуля />
- Урок 2. Первые команды в Windows PowerShell
Change directory in PowerShell
My PowerShell prompt’s currently pointed to my C drive ( PS C:\> ). How do I change directory to a folder on my Q ( PS Q:\> ) drive?
The folder name on my Q drive is «My Test Folder».
8 Answers 8
Unlike the CMD.EXE CHDIR or CD command, the PowerShell Set-Location cmdlet will change drive and directory, both. Get-Help Set-Location -Full will get you more detailed information on Set-Location , but the basic usage would be
By default in PowerShell, CD and CHDIR are alias for Set-Location .
(Asad reminded me in the comments that if the path contains spaces, it must be enclosed in quotes.)
How to change drive and the directory in Windows PowerShell ?
This tutorial guides you how to change drive and the current directory in Windows PowerShell to different drive or directory.
Change directory in Windows PowerShell
There are many ways to change drive and directory in Windows PowerShell. The following are the different ways to do this.
Set-Location
Set-Location can be used to set current working location to a specified location as shown below.
For Example, Set-Location -Path E:/Work will set current working location to E:\Work
To know the path of your current directory location, you can use the following command Get-Location
Note, built-in Windows PowerShell aliases like “cd“, “chdir” can be used instead of “Set-Location” which is explained above.
cd command
The following example shows how to use “cd” instead of “Set-Location” to change the current working directory.
chdir command
As said, “chdir” can also be used instead of “Set-Location” from PowerShell to change the directory as shown below
Change directory to previous directory in Powershell
I am a Linux guy, but am trying to be open-minded and learn some Powershell. I miss the ability to cd — back to a previous directory, like in *nix shells. Is there a similar command in Powershell—one that would allow me to return to my previous directory?
8 Answers 8
I’ve had differing luck with cd +/- even though it should work.
pushd and popd have been around a long time and do the job nicely but I wasn’t sure if they were officially supported in Powershell — I’ve just discovered they are actually aliases to Push-Location and Pop-Location so are current and supported, seems to be the best way to go:
Previous suggested of using aliases to swap out the standard cd command are a good idea but in scripting I’m just using the real cmdlet name for clarity.
Not in exactly the same fashion that I am aware of. One option is to use pushd instead of cd. Then popd will take you back.
You could also change your profile so that whenever a new prompt comes up (basically whenever you hit enter). It would get the PWD and compare that to the previous one. If they are different, then put that value onto a stack. Then you would include another function in your profile called something like cdb that would pop the last item off the stack and cd to it.
This sounded like fun so I came up with a solution. Put all this code into your profile (about_Profiles).
Now you can cd just like normal and bd will take you back on location in your location history.