File Management Commands
Command Prompt makes it easy to create, copy, delete, and manage files. Let’s dive into some essential file management commands:
-
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.
- Usage:
-
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.
- Usage:
-
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 namedcopy_example.txt
.
- Usage:
-
del
— Delete Files- Usage:
del filename
- Example:
del example.txt
- What it does: Deletes the file
example.txt
from the current directory.
- Usage:
-
rename
— Rename Files- Usage:
rename old_name new_name
- Example:
rename copy_example.txt final_example.txt
- What it does: Renames
copy_example.txt
tofinal_example.txt
.
- Usage:
Directory Management Commands
In addition to managing files, Command Prompt lets you efficiently create and delete directories.
-
mkdir
— Create a Directory- Usage:
mkdir folder_name
- Example:
mkdir MyFolder
- What it does: Creates a new directory named
MyFolder
in the current location.
- Usage:
-
rmdir
— Remove a Directory- Usage:
rmdir folder_name
- Example:
rmdir MyFolder
- What it does: Deletes an empty directory named
MyFolder
.
- Usage:
-
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.
- Usage:
Useful Shortcuts and Tips
-
Wildcards (
*
and?
):- Use
*
to represent multiple characters and?
to represent a single character. - Example:
Deletes alldel *.txt
.txt
files in the current directory.
- Use
-
Redirection:
- Use
>
to redirect output to a file and>>
to append output. - Example:
Saves the directory listing to a file nameddir > directory_list.txt
directory_list.txt
.
- Use
-
Command History:
- Use
F7
to view a list of previously executed commands. - Press
F3
to repeat the last command.
- Use
Practice Tasks
To solidify your learning, try these tasks:
- Create a file named
test.txt
with the text "Learning Command Prompt." - Copy
test.txt
to a new file calledbackup.txt
. - Rename
backup.txt
tofinal.txt
. - Create a folder named
TestFolder
and movefinal.txt
into it. - 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!
0 Comments