Command Prompt Basics: Part 2

File Management Commands

Command Prompt makes it easy to create, copy, delete, and manage files. Let’s dive into some essential file management commands:

  1. echo — Create a File

    • Usage: echo text > filename
    • Example:
      echo Hello World > example.txt
      
    • What it does: Creates a file named example.txt and writes "Hello World" into it.
  2. type — View File Contents

    • Usage: type filename
    • Example:
      type example.txt
      
    • What it does: Displays the content of example.txt in the Command Prompt window.
  3. copy — Copy Files

    • Usage: copy source_file destination_file
    • Example:
      copy example.txt copy_example.txt
      
    • What it does: Copies the contents of example.txt to a new file named copy_example.txt.
  4. del — Delete Files

    • Usage: del filename
    • Example:
      del example.txt
      
    • What it does: Deletes the file example.txt from the current directory.
  5. rename — Rename Files

    • Usage: rename old_name new_name
    • Example:
      rename copy_example.txt final_example.txt
      
    • What it does: Renames copy_example.txt to final_example.txt.

Directory Management Commands

In addition to managing files, Command Prompt lets you efficiently create and delete directories.

  1. mkdir — Create a Directory

    • Usage: mkdir folder_name
    • Example:
      mkdir MyFolder
      
    • What it does: Creates a new directory named MyFolder in the current location.
  2. rmdir — Remove a Directory

    • Usage: rmdir folder_name
    • Example:
      rmdir MyFolder
      
    • What it does: Deletes an empty directory named MyFolder.
  3. rmdir /s — Remove a Directory with Contents

    • Usage: rmdir /s folder_name
    • Example:
      rmdir /s MyFolder
      
    • What it does: Deletes the directory MyFolder along with all its files and subfolders. You’ll be prompted to confirm.

Useful Shortcuts and Tips

  1. Wildcards (* and ?):

    • Use * to represent multiple characters and ? to represent a single character.
    • Example:
      del *.txt
      
      Deletes all .txt files in the current directory.
  2. Redirection:

    • Use > to redirect output to a file and >> to append output.
    • Example:
      dir > directory_list.txt
      
      Saves the directory listing to a file named directory_list.txt.
  3. Command History:

    • Use F7 to view a list of previously executed commands.
    • Press F3 to repeat the last command.

Practice Tasks

To solidify your learning, try these tasks:

  1. Create a file named test.txt with the text "Learning Command Prompt."
  2. Copy test.txt to a new file called backup.txt.
  3. Rename backup.txt to final.txt.
  4. Create a folder named TestFolder and move final.txt into it.
  5. Delete the folder and its contents.

What’s Next?

In Part 3, we’ll cover:

  • Advanced navigation techniques.
  • Using environment variables.
  • Automating tasks with batch scripts.

Keep practicing, and don’t hesitate to ask questions in the comments. Let’s keep mastering Command Prompt together!

Post a Comment

0 Comments