Using Windows Command Prompt or CMD correctly - Part 2

Using Windows Command Prompt or CMD correctly – Part 2

Using Windows Command Prompt or CMD correctly for everyone. In this article I will show you what a path is, how to navigate through folders, open text files, rename folders, move files and delete folders.

If this is the first time you read about Windows Command Prompt or CMD, feel free to check out our previous article. For the continuing article please do not forget to confirm every input with Enter; otherwise the CMD does not recognize that your command should be executed.

Path (pathname) & space at Windows command prompt

A path designates drives, files or a directory with a character string. Several pieces of information can be used in the path. The more names separated with “” within a path name, the deeper a file exists in the directory tree. A path is composed like this:

C:/Users/Name/Desktop/CMD-Tutorial/final-file/test-file-for-cmd
Directory tree

If there are spaces in the path name, quotation marks must be placed once before and once after the entire path. If the “quotation marks at the top” are not used, the command cannot be executed, because the CMD automatically recognizes a new parameter after a space (e.g. a new path that may not even exist). Correct in the case of spaces would therefore be like this:

"C:/Users/Name/Desktop/CMD-Tutorial/final-file/test-file-for-cmd"

For future reference and for the love of your computer’s administrator, all naming for files, folders, usernames, etc. should not contain spaces. This can save time and nerves.

Absolute & relative path

The path C:UsersNameDesktopCMD-Tutorialfinal-filetest-file-for-cmd is an absolute path. This path is unambiguous because it is written out in full. Note that the command that precedes the path is executed at the last parameter.

A relative path helps you to navigate within the CMD, starting from the current working directory (CWD). The relative path is a position specification of the directory to be reached in relation to the current working directory (CWD). It is an alternative to the specification of absolute path names. For smaller navigation steps, such as a simple change to a subfolder, only the name of the folder is sufficient after the command as path name. This makes the exact specification of an absolute path name – which can be very long – unnecessary.

As examples for relative paths I name two possibilities to get to a subfolder:

C:/Users/Name/Desktop>dir CMD-Tutorial

or

C:/Users/Name>dir desktop/CMD-Tutorial

So: command space relative path

If I were to specify the above command with an absolute pathname, it would look like this:

C:/Users/Name>dir C:/Users/Name/desktop/CMD-Tutorial

Navigation commands in Windows command prompt

To navigate through folders faster or to find your way around better, you can use the following commands:

  • Dir (with and without path)
    Dir without path shows you in the form of a list which branches or data exist from this location. The command C:UsersUsername>dir desktop shows me what is stored on my desktop.
  • cd
    The response to the query cd without specifying an additional parameter will show you which path you are currently working with or where you are currently located in the directory tree.
  • cd ..
    .. is the relative path name for the next upper directory. So Cd … makes you move up one level within the path before the > within the directory tree. So C:UsersUsername> becomes C:Users>. If you use cd ../.. you get to the next but one upper level directory.
  • cd Pathname
    Cd Pathname is used to get deeper into the directory tree before >. For this purpose, after the cd command, you must name the path you want to arrive at.
    Example:
    C:> cd usersName
    C:usersName>
  • &&
    && is used to specify multiple commands in one line. Entering cd … && dir lists all directories and files in the upper-level directory.

Open a file with CMD

To open a file with the CMD you don’t necessarily need a command. With my file test-file-for-cmd it is sufficient to enter only the relative path for it. Then the text file opens automatically. If it doesn’t work for you and your file, you can insert the Start command before the path. Usually files, e.g. also photos, are opened in default programs of Windows.

For me the command with the relative path looks like this:

C:/Users/Name/Desktop/CMD-Tutorial/final-file>start test-file-for-cmd

The text file opens:

Rename file or folder

To rename a file or folder, you need one of the following commands: ren OldName NewName or rename OldName NewName. I want to rename test-file-for-cmd to test-txt-for-cmd. The command then reads like this:

C:/Users/Name/Desktop/CMD-Tutorial/final-file>ren test-file-for-cmd test-txt-for-cmd

Think of possible spaces, if you work with spaces you would have to write it like this:

C:/Users/Name/Desktop/CMD-Tutorial/final-file>ren "test-file-for-cmd" "test-txt-for-cmd"

Move file to another folder

If you want to keep your computer’s storage space clean or just want to reorder it and this should be controlled only by the CMD, then you can indeed move or delete files only by means of the CMD. If you know the paths of the files or folders, you can start moving them directly. For this you use the command move.

C:/Users/Name/Desktop/CMD-Tutorial>move "final-filetest-txt-for-cmd" "final-file2"

After moving a file you will get a feedback that a file has been moved (if it is only one file).

Delete an empty folder

You can delete an empty folder with the command rmdir. I delete now the folder final-file.

C:/Users/Name/Desktop/CMD-Tutorial>rmdir final-file

If you want to check first if the folder you want to delete is really empty, you can simply use the dir command.

Delete folder including files

Now I will delete the folder final-file2. However, in this folder there is still the file test-txt-for-cmd. To delete the folder, I enter the following:

C:/Users/Name/Desktop/CMD-Tutorial>rmdir final-file2/s

The /s is crucial. This signals the CMD that the folder should be deleted together with the data there. For security reasons you will be asked if you want to delete the folder. In brackets you will see the answer options when executing the command. In my case it was Y and the N. After typing Y and confirming with Enter, the folder and its contents are deleted. This kind of query rarely occurs when working with the Windows command prompt, so you should be sure in advance what and how you want to delete.

Table of Content

Mastercard
VISA
SEPA
SWIFT
PCI Security Standards Council
Mastercard
VISA
SEPA
SWIFT

PCI Security Standards Council

Subscribe to our newsletter and get all the latest news as a PayPodo insider!

Would you like to receive all the latest news from PayPodo? Then you’ve come to the right place! Register today and don’t miss anything anymore!

PayPodo operates under CustomHash AG, a company registered in Germany with Legal Entity Identifier 391200VTCFSYUNN7YA32 and with offices at Oberwallstraße 6/4, 10117 Berlin, Germany. CustomHash AG (Certificate) is an authorized Electronic Money Institution intermediary of Verified Payments UAB (Licence No. 27), which is a licensed Electronic Money Institution supervised by Bank of Lithuania under the Electronic Money Regulations.