Command Prompt: 11 basic commands you should know (cd, dir, mkdir, etc.) | Digital Citizen

How to change the directory (folder) in Command Prompt (CMD)

The first command from the list is CD (Change Directory). This command enables you to change the current directory or, in other words, to navigate to another folder from your PC. For instance, the command CD takes you to the top of the directory tree.

To see how it works, after you open the Command Prompt, type cd and press Enter on your keyboard. You should see how the CD command takes you to the top of the directory tree. In this case, to the “C:” drive.

Note that the Command Prompt is not case sensitive, meaning that you can type commands using capital letters, lowercase or any combination of them. The commands CD, cd or Cd, all work the same way.

Going back to the “CD” command, now you are working on the root of the “C:” drive. If you need to go to a specific folder from this drive run the command “CD Folder.” The subfolders must be separated by a backslash character: “.

When you need to go one folder up, use the “cd..” command. Let’s assume that you want to go back to the Windows folder. Type “cd..” and press Enter on your keyboard.

The effect is that your current directory changes to “C:Windows.”

How to open Command Prompt from the Start Menu

On your Windows 10 PC, open the Start Menu and go to the Windows System shortcuts folder. There, you’re going to find a Command Prompt shortcut: click or tap on it to open CMD.

. Ask Cortana to open Command Prompt

If you have a microphone installed on your Windows 10 computer or device, you can also tell Cortana what you want to do. Say “Hey Cortana” if you enabled her to answer you anytime you call for her, or click/tap on her icon next to the search field on your taskbar. Then, ask Cortana to “open Command Prompt.”

. How to open Command Prompt while installing Windows 10

We have another neat method of opening Command Prompt even when Windows 10 is not installed on your computer. It also works when your Windows 10 is corrupted that it can’t boot properly. Use a Windows 10 installation media to boot your computer or device.

It’s as simple as that! 🙂

How to change the drive in Command Prompt (CMD)

To access another drive, type the drive’s letter, followed by “:”. For instance, if you wanted to change the drive from “C:” to “D:”, you should type “d:” and then press Enter on your keyboard.

To change the drive and the directory at the same time, use the cd command, followed by the “/d” switch. The “/d” parameter is used to change the current drive to a specific folder from another disk volume.

For instance, if you are now on the “D:” drive and you want to go back to the Windows folder from the”C:” drive, you should type “cd /d C:Windows” and press Enter on your keyboard, like in the following screenshot.

NOTE: By typing only the drive letter you automatically move to your most recent location on that drive. For instance, if you are on “D:” drive and type “cd c:windows” nothing seems to happen. However, if you type “c:” then the working folder changes to “c:windows,” assuming that it was the last folder you worked with on your “C:” drive.

Open Command Prompt using search

In Windows 10, one of the fastest ways to open Command Prompt is to use search. Inside the search field from your taskbar, enter command or cmd. Then, click or tap on the Command Prompt result.

How to open Command Prompt from the Run box

One of the quickest ways to open Command Prompt in Windows 10 is via the Run window. Press the Win R keys on your keyboard, then type cmd, and press Enter on your keyboard or click/tap OK.

How to view the contents of a directory in Command Prompt (CMD)

You can view the contents of a folder by using a command called DIR. To test it, we have created a folder named Digital_Citizen on the D: drive, with several files and subfolders. You can see them in the screenshot below.

The last time, our working folder was “C:Windows.” To navigate to the folder mentioned above, we have to use the command “cd /d D:Digital_Citizen.” To view the contents of the folder, type DIR, and press Enter.

:/>  Как работают видеокодеки? Разбор |

How to create a new directory with Command Prompt (CMD)

You can make a new folder using the MKDIR (Make Directory) or the MD command. The syntax of these commands is “MKDIR Folder” or “MD Folder.”

Let’s say we need to create a new folder called Digital_Citizen_Life that is going to be placed in the “D:Digital_Citizen” folder. To do that, we need to type “mkdir Digital_Citizen_Life” and then press Enter, as shown below.

To test if it worked, use the DIR command again. The newly created folder appears in the list.

NOTE: Do not forget that all these commands depend on the current location in the Command Prompt. For instance, if you are on the “C:” drive and type “MKDIR test,” the new folder is created in the root of the “C:” drive.

Another way to create a folder that does not involve being in the desired folder is to type the complete path of the new folder. For example, if you are working on the “D:” drive and you want to create a new folder in “C:,” called other_stuff, type “mkdir c:other_stuff” and then press Enter.

When you need to create a folder with subfolders at the same time, you can use the “MKDIR FolderSubfolder” command. For instance, if we type “mkdir Digital_Citizen_TestsBetaTest1” three folders are created: Digital_Citizen_Tests, Beta and Test1, in a tree-like structure.

How to rename files and folders with Command Prompt (CMD)

To rename files and folders, you need to use the REN (Rename) command. To rename folders, type “ren Folder NewFolderName.” For example, if we wanted to rename the Digital_Citizen_Tests folder to Digital_Citizen_Final_Tests, we should run “ren Digital_Citizen_Tests Digital_Citizen_Final_Tests” and press Enter.

To rename a file, use the same command, like this: “ren filename.extension newname.extension”. For instance, to rename the Digital_Citizen_Picture1.bmp file to Image0.bmp, we have to run the command “ren Digital_Citizen_Image1.bmp Image0.bmp” command.

Read the second page of this tutorial if you want to learn how to copy files and folders, delete files and folders, start an application, and get help when using the Command Prompt.

How to copy files with Command Prompt (CMD)

The Copy command allows you to copy files from one location to another. To use this command, type “copy locationfilename.extension newlocationnewname.extension”.

For example, let’s use this command to copy the Image0.bmp file from the Digital_Citizen folder located on the “D:” drive to the “D:Digital_CitizenDigital_Citizen_Tests folder. To make things more interesting, we want the file to be named Testing_Picture1.gif.

To do all that, we must type the command “copy D:Digital_Citizenimage0.bmp D:Digital_CitizenDigital_Citizen_Teststesting_picture1.gif” followed by Enter. You should also receive a confirmation of the operation, as you can see below.

If you are copying within the same directory, you do not have to put the path in the command. As an example, let’s copy Digital_Citizen_Notes.txt from “D:Digital_Citizen” in the same folder, only with a different extension: let’s say Digital_Citizen_Notes.docx.

To do that, we have to run the command “copy Digital_Citizen_Notes.txt Digital_Citizen_Notes.docx.”

How to copy folders (and their contents) with Command Prompt (CMD)

To copy a folder and its content from a location to another, use the XCOPY command followed by the “/s /i” operators. Let’s assume that we need to copy a folder from “D:Digital_Citizen” to “C:Backup_Digital_Citizen.

” To do that, we have to run the command “xcopy /s /i d:Digital_Citizen c:Backup_Digital_Citizen.” The “/s” parameter ensures that all the directories and subdirectories are going to be copied, except the ones that are empty.

How to delete files with Command Prompt (CMD)

The DEL (Delete) is used to delete files from the folders you have created. To delete all the files from a folder, you can run the command “del folder.” For instance, from the directory, Digital_Citizen found on the “D:” drive if we want to delete all the files from the Digital_Citizen_Tests folder, type the command “del Digital_Citizen_Tests.

NOTE: To also delete hidden files from the folder, you must add the “/h” parameter. Also, note that the DEL command does not work for deleting folders – for that, you have to use the RD command of which you can read in the next section of this tutorial.

If you need to delete a single file, use the DEL command followed by that file’s name. For instance, to delete the file Digital_Citizen_Notes.txt from “D:Digital_Citizen,” we should run the command “del Digital_Citizen_Notes.txt.”

:/>  Командная строка | Русскоязычная документация по Ubuntu

Here is a list of useful DEL combinations that are worth mentioning:

  • DEL *.DOCX – delete all files with the DOC extension (you can use any file extension necessary, DOCX is just an example);
  • DEL Test*.* – delete all files beginning with Test;
  • DEL *.* – delete ALL files from the current folder.

How to delete folders with Command Prompt (CMD)

The DEL command cannot be used to delete folders. Therefore we must use another command to remove any empty folder: RD (Remove Directory). We have previously deleted all the files from the Digital_Citizen_Tests folder. It is now time to delete the directory too, by typing “RD Digital_Citizen_Tests.”

Can you give me cool cmd tricks?

1. Use Ctrl-C to Abort a Command

Just about any command can be stopped in its tracks with the abort command: Ctrl-C.

If you haven’t actually executed a command, you can just backspace and erase what you’ve typed, but if you’ve already executed it then you can do a Ctrl-C to stop it.

Warning: Ctrl-C isn’t a magic wand and it can’t undo things that aren’t undoable, like a partially complete format command. However, for things like the dir command that seem to go on forever or questions you’re asked at the prompt that you don’t know the answer to, the abort command is an excellent Command Prompt trick to know.

2. View a Command’s Results One Page (or Line) at a Time

Ever run a command, like the dir command, that produces so much information on the screen that it’s almost useless? You’re not alone.

One way around this is to execute the command in a special way so whatever information is generated is shown to you one page, or one line, at a time.

To do this, just type the command, the dir command for example, and then follow it with the pipe redirection operator and then the more command.

For example, executing dir /s | more will generate the thousands of lines of results that you expect from the dir command, but the more command will pause each page of results with — More — at the bottom of the page, indicating that the command is not done running.

Just press the space bar to advance by page or press the Enter key to advance one line at a time.

See Command Prompt Trick #7 below for a different solution to this problem.

3. Run Command Prompt as an Administrator Automatically

Many commands require that you execute them from an elevated Command Prompt in Windows – in other words, execute them from a Command Prompt that’s run as an administrator.

You can always right-click on any Command Prompt shortcut and choose Run as administrator but creating a shortcut to do the same thing can be a huge time saver if you’re a frequent Command Prompt power user.

To complete this Command Prompt trick, just create a Command Prompt shortcut on the desktop, enter the shortcut’s properties and then select the Run as administrator box located in the Advanced button on the Shortcut tab.

4. Become a Command Prompt Power User with Function Keys

The fact that the function keys actually do something in the Command Prompt is maybe one of the best kept secrets about the tool:

F1: Pastes the last executed command (character by character)
F2: Pastes the last executed command (up to the entered character)
F3: Pastes the last executed command
F4: Deletes current prompt text up to the entered character
F5: Pastes recently executed commands (does not cycle)
F6: Pastes ^Z to the prompt
F7: Displays a selectable list of previously executed commands
F8: Pastes recently executed commands (cycles)
F9: Asks for the number of the command from the F7 list to paste

Command Prompt Trick #17 is full of arrow key shortcuts, a few of which are similar to these function key tricks.

5. Hack the Prompt Text

Did you know that the prompt itself in the Command Prompt is completely customizable thanks to the prompt command? It is, and when I say customizable, I mean really customizable.

Instead of C:>, you can set the prompt to any text you want, have it include the time, the current drive, the Windows version number, you name it.

:/>  GTA 4 вылетает :: Grand Theft Auto IV: The Complete Edition General Discussions

One useful example is prompt $m$p$g which will show the full path of a mapped drive in the prompt, alongside the drive letter.

You can always execute prompt alone, without options, to return it to its sometimes boring default.

6. Get Help for Any Command

Believe it or not, the help command does not provide help for every Command Prompt command. However, any command can be suffixed with the /? option, usually called the help switch, to display detailed information about the command’s syntax and often times even some examples.

I doubt that the help switch is the coolest Command Prompt trick you’ve ever heard of, but it’s hard to disagree that it’s one of the more useful.

Unfortunately, neither the help command nor the help switch offer much in the way of explaining how to interpret the syntax. See How To Read Command Syntax if you need help with that.

7. Save a Command’s Output to a File

An incredibly useful Command Prompt trick is the use of redirection operators, specifically the > and >> operators.

These little characters let you redirect the output of a command to a file, giving you a saved version of whatever data the command produced in the Command Prompt window.

Let’s say you’re about to post a computer problem to an online forum, like my computer support forum for example, and you want to provide really accurate information about your computer. An easy way to do that would be to use the systeminfo command with a redirection operator.

For example, you might execute systeminfo > c:mycomputerinfo.txt to save the information provided by the systeminfo command to a file. You could then attach the file to your forum post.

See How To Redirect Command Output to a File for more examples and a better explanation of how to use redirection operators.

8. View Your Hard Drive’s Entire Directory Structure

I think one of the neatest little commands is the tree command. With tree, you can create a kind of map of your computer’s directories.

Execute tree from any directory to see the folder structure under that directory.

Tip: With so much information, it’s probably a good idea to export the results of the tree command to a file. For example, tree /a > c:treeresults.txt, just as explained in Command Prompt Trick #7.

9. Customize the Command Prompt Title Bar Text

Tired of that Command Prompt title bar text? No problem, just use the title command to change it to whatever you like.

For example, let’s say your name is Maria Smith, and you want to express your ownership of the Command Prompt: execute title Property of Maria Smith and the Command Prompt’s title bar will change immediately.

The change won’t stick, so the next time you open Command Prompt the title bar will be back to normal.

The title command is usually used to help give a custom appearance in script files and batch files… not that I’m saying titling it with your name isn’t a good idea!

10. Copy From the Command Prompt

As you may or may not know, copying from the Command Prompt is not as easy as copying from other programs, which is part of the reason why saving a command’s output to a file, Command Prompt Trick #7, is so handy.

But what if you do just want to copy a short section of text to the clipboard? It’s not too hard but it’s not very intuitive either.

Right-click anywhere in the Command Prompt window and choose Mark. Now, highlight with your left mouse button whatever you’d like to copy. Once your selection is made, press Enter.

Command and conquer your windows pc

This article can only give you a taste of what’s hidden within the Windows command line. When including all variables, there are literally hundreds of commands. Download Microsoft’s command line reference guide (in Edge or Internet Explorer) for advanced support and troubleshooting.

Tired of the command prompt? Time to try the new Windows Terminal!

About The Author.

Оставьте комментарий

Adblock
detector