Basic operations for Windows powershell--directory files

Source: Internet
Author: User

Windows PowerShell (i) basic operations for directories and files

You can browse directories, create, move, delete directories, and files from the system with some commands. The operation of directories and files is based on the use of command-line tools. Windows users open Powershell, and then try these next commands.

(1) Check your current location pwd

Powershell, as well as the terminal, displays your current directory by default on the left side of the cursor. You can also use the PWD (print working directory) command to see where you are now.

C:\Users\Administrator, which is where I am now, is the working directory that is entered when the Powershell is opened by default, C \ Is the system's drive letter, which is unique to Windows,

There is no drive letter on Mac and Linux, and users are where all user documentation is stored in the system. Administrator is the name of the user who is currently logged on to the system. This C:\Users\Administrator is Administrator the user's home directory (home).

(2) Show the current directory of things LS or dir

To see what is under a directory, with the LS command, you can specify the path to a directory at the back of the command, which shows what is in the specified path, and if you use LS directly, it will show you what is in your current location.

Windows Powershell will show more detail about everything under the directory, such as permissions on files and directories, the time of the last update, and so on.

    • You can add a path after the LS command, which shows what's underneath this path, which can be either an absolute path or a path path. For example, take a look at all the things under the user's home directory:
LS Desktop
    • The above uses a relative path, that is, the LS command will be under the current directory to see what is in the desktop directory. If you use an absolute path, this is the case:
LS C:\Users\Administrator\destop

Note : The Windows path is preceded by a backslash (\), but in Powershell you can also use a slash (/).

(3) Displaying the directory structure in a tree shape

Format: Tree [X:][path][parameter]

Parameter explanation:

/a specifies that the tree displays the rows of the linked subdirectory using characters rather than graphic characters

/F Displays the file names in each directory

Tree

R

tree/a

tree/f

(4) Empty the command line above the display clear

If you feel that there are too many things on the screen, you can use the clear command if you want to clear the page. You have a refreshing command window.

(5) Symbols in the path/~./...User home Directory ~

The operating system assigns a specific directory to each user who logs on to the system, and the name of the directory is usually the same as the user's name, and the document belonging to the user is stored under this directory.

This directory is the user's home directory, which is represented in the command line by the ~.

root directory/

A slash (/), which represents the root of the system, is represented by a root directory under a certain drive letter, such as LS/This command will show everything underneath the C packing directory. Both the MAC and Linux represent the root directory of the system.

current directory./

./OR. , which means the current directory, such as what you want to do with the current directory, can be added to the front of the path./, such as the LS command described above, you want to list the current directory of things, you can use LS.

However, it is generally possible to omit it, directly using the LS command to show what is under the current directory.

top-level directory: /

You want to deal with the contents of the upper level in your location, you can use one at the beginning of the path. /,

For example, if you want to display something from the previous level of the current directory, you can enter LS. / 。

One.. /Represents the previous level of the directory, the first two levels are: /.. / 。

(6) Enter or exit a directory CD

Format: CD [[/d][x:][path][.]]

Parameter explanation:

.. Go to the top level directory

/d quickly change the current directory

/? Display Help information in the command prompt

\ go back to the root directory

(7) Create directory mkdir

Create a new directory at the specified location, using mkdir (make directory), followed by the name of the directory you want to create: mkdir directory Name

My current location is on the desktop and I'm going to create a directory called projects on the desktop: mkdir projects

If you need to create a directory structure, you may want to create a subdirectory under a directory.

On Windows, you can add the path to the directory you want to create directly after the mkdir command, and all of the directories above that path will be created if they don't already exist.

(8) Mobile directory and file MV

Move the directory or file to a new location, using the MV (move) command, which can also be used to rename a directory or file.

The command is followed by something to move, a space, and then a new position to move to.

    • MV Source Target

For example, I'm going to put the README in the website on the table. MD This directory to move to the desktop, first determine your current location is on the desktop, you pwd can view the current location,

If not, you can use CD ~/desktop to enter the desktop. LS View website Inside there is a readme.me, is the readme.me to move understand to do on the surface

In the above command, the./represents the current directory, that is, where you are, this command means to move the directory below the current directory to the readme.md of the website below the current directory.

That is, on the desktop.

Such as:

Below, you can put this readme.md again under the website directory.

If the projects directory already exists, it means to move the README.MD directory into the projects directory,

If the projects directory does not exist, it will rename the Readmet.md directory to website.

Note: When moving a file, the file should be moved to the end of the position must be added/, or the MV name will be the file you want to move to the location you want to move to.

(9) Copying directories and files: CP

The CP (copy) name can copy the specified file or directory, first specify what to copy, a space to separate, and then the location to copy to.

CP Source Target

You can create a new blank file on your desktop, such as README.MD, and then copy it to the bottom of the Users/administrator/test directory.

CP readme.md users/administrator/test/

To copy the directory, you need to add an-r parameter, such as copy the test on the desktop to the desktop, named Projects_bak.

Cp-r Test Projects_bak

(10) Delete directories and files: RM

To delete the specified directory or file, with the RM (remove) command, after it is added to delete the thing on the line, when the directory is deleted, you need to use a-R parameter, in addition, you can add a-f parameter, so that the deletion of files in the directory will not appear when prompted. Note Using the RM command above Windows Powershell does not require the use of parameters.

For example, my location is on the desktop, there is a previously created file called Readme.md this file, delete this file can be like this:

    • RM readme.md

And then delete the Projects_bak directory on the desktop:

    • RM-RF Projects_bak

Windows Powershell does not require the use of parameters:

    • RM Projects_bak

ren: Renaming a directory

Format: ren [x:][path]filename1 filename2

Parameter explanation:

[x:] [PATH]FILENAME1 Specifies the location and name of the folder or file to be renamed

Filename2 new file name specified when renaming files

Get-help is a fairly important cmdlet that can query all Windows PowerShell directives and documentation. For example:
    • GET-HELP *: Lists all topics, including directives and concepts.
    • Get-help * | MORE: Lists all the topics, including instructions and concepts, and pauses when the full window is displayed.
    • Get-help about*: Lists all the conceptual topics.
    • Get-help get*: Lists the topics for all get starts.
    • Get-help {< instruction name or subject name;}: Lists instructions for the specified instruction or topic, such as Get-help dir can query the use of the dir instruction.

Basic operations for Windows powershell--directory files

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.