Comprehensive Guide to Using the Command Prompt for File and Directory

Comprehensive Guide to Using the Command Prompt for File and Directory Photo
Author: Tatyana Milkina

Absolute and Relative File Paths

File paths can be either absolute or relative:

  • Absolute paths point to a specific location in the file system, starting from the root directory, regardless of the current working directory or other factors.
  • Relative paths are defined concerning the current working directory of the user or application.

Navigating Directories

To move from one directory to a subdirectory, use the following command:

cd [directory]
or
cd [directory/subdirectory]

To move up from a subdirectory to its parent directory, use:

cd..
To switch to a completely different directory (not the parent of the current directory):
cd [\directory]

Changing Drives (Windows)

To switch to another drive, enter the drive letter followed by a colon:

D:​

Essential Command Line Operations

  1. Open Command Prompt:
    Use the shortcut Windows + R, then type cmd.

  2. Request Command Help:
    Enter the command:

    help​
  3. List All Folder Contents:

    Use the command:

    dir
  4. Browse Command History:
  5. Use the ↑ (Up Arrow) and ↓ (Down Arrow) keys to scroll through previous commands.

  6. Autocomplete Folder Contents:
    Press the Tab key to cycle through items in the current directory. Use Shift + Tab to cycle in reverse.

  7. Filter by Initial Letters:
    Type a letter or sequence of letters and press Tab to see files and folders starting with those characters (e.g., "s" for system, system32, system.ini, etc.).

Creating and Running Batch Files

You can create script files with the extensions:

  • .bat (for Windows)
  • .sh (for Linux).

These files can contain multiple commands and be executed via the command line or file explorer.

Note: When running from File Explorer, the Command Prompt window will close immediately after execution. To keep it open and view the output, add the following line at the end of your file:

pause
 
Курс 'Java для начинающих' на Udemy Курс 'Java для начинающих' на Udemy
Read also:
Comments