Command Prompt basics: Working with files and folders
Tired of using File Explorer to navigate your files? Alright, that may not be you, unless you’re a developer or an IT professional. Developer or not, basic command line knowledge is always good-to-have though.
In this guide, we’ll present some common file manipulation commands, which you can use when working in the terminal.
Traversing your file system from Command Prompt (or from PowerShell or from Windows Terminal) requires two basic commands:
dir. The first (change directory) enables you to move through folders within your command prompt window.
For example, if you’re in a folder with sub-directories of “Folder 1” and “Folder 2”, type
cd "Folder 2" to move into the Folder 2 sub-directory. Use
cd .. to move up a level. The path at the start of the Command Prompt input line always indicates your current directory.
Once you’re in a directory, use the
dir command to view the files and folders within. Type
dir to get a list of everything in your current directory (displayed at the start of the command prompt). Alternatively, use
dir "Folder Name" to list the contents of a named sub-directory.
We’ve found the right folder and seen the files within. Now we want to view the contents of a file. Use the
type command to inspect what’s inside text-like files. For example,
type my-article.txt will display the contents of the file right within the command prompt window.
To update the contents of a file, use the
echo command to replace its contents. Running
echo "my new text" > my-article.txt will result in the
my-article.txt file having “my new text” as its content. You can verify this with the
If you’d rather add content to the end of the file, instead of overwriting it, use
>> instead of
> in the command above. This operator appends content to the end of the file, preserving what’s already there.
These commands are simple but powerful when combined together. We’ve only covered the absolute basics here, which enable you to view files and folders on your PC. A few other helpful commands include
mkdir <DIRECTORY> (create a new directory),
copy <SOURCE> <DESTINATION> (copy files) and
move <SOURCE> <DESTINATION> (move files).
To get more information on these commands, we encourage you to refer to another command:
help, followed by the name of a command (e.g.
help mkdir) to get detailed help information within your command prompt window. You should now be equipped to explore your PC with Command Prompt and keep learning as you do so! Try running
help on the commands discussed in this article to discover further features which they support.