How to

How To Use Command Prompt To List Files

Are you wondering to use the command prompt to list files? If you are tired of using File Explorer then here we present some common file manipulation commands, which you can use while working in the terminal.

Traversing your file system from Command Prompt needs two basic commands: cd and dir. Initially, (modify directory) allows you to move through folders that are present in your command prompt window.

How To Use Command Prompt To List Files:

Use Command Prompt

For instance, if you’re working with a folder with the sub-directories of “Folder 1” and “Folder 2”, enter cd "Folder 2" to head over the Folder 2 sub-directory. You can also use cd .. to move up a level. At the start of the Command Prompt input line always shows your current directory.

After you reach in a directory, you can then use the dir command to check the files and folders within. Simply enter dir to get a list of everything in your directory. On the other hand, you can use the command dir "Folder Name" to list the contents of a named sub-directory.

The directory where cmd is located is known as the current working directory.
From here we can use the “dir” command to check every folder or file in this directory.

Dir

Now we’ve found the exact folder and view the files within. Now we like to view the file contents. Simply use the command type to check what’s inside text-like files. For instance, type my-article.txt will show the contents of the file right within the command prompt window.

If you want to update the file contents, you can then use the echo command to replace its contents. Executing echo "my new text" > my-article.txt will result in the my-article.txt file with “my new text” as its material. You can also check this using the type command!

Add Content At The End Of File:

If you want to add content to the end of the file, rather than overwriting it, simply use >> besides > in the command above. This operator adds content at the end of the file.

However, the commands are quite simple but stronger when merged together. We’ve only covered the absolute basics here, which allows you to check folders or files on your PC. Some other essential commands include mkdir <DIRECTORY> (create a new directory), copy <SOURCE> <DESTINATION> (copy files) and move <SOURCE> <DESTINATION> (move files).

Understanding Commands -> Command Prompt Or DOS

Working with files and folders

Moving into a directory

Now you know the list of directories in the current directory. If you want to move into one of those directories then check this command. You can use the cd command, to move into the Desktop type cd desktop and hit Enter. After you’ve moved into a new directory, the prompt should modify.

Understand Files

In the Desktop directory, there are a total of 23 files and 7 directories. It represents various file types. In Windows, you know the files having icons that help you to represent the file type. In the command line, the same thing is fulfilled by the file extensions. For instance, “abc posts.txt” is a text file because it has a .txt file extension.

Some users concerned with the executable files. These files ends with .exe, .com, and .bat. When you enter the name of each file into the command line, the program runs, which is similar to double-tapping a file in Windows.

Creating a directory

If you want to create a directory in the recent directory, you can then use mkdir command. For instance, create a directory like “abc” by typing mkdir abc at the prompt. If created successfully, you should enter to the prompt with no error message. When the directory is created, head over to that directory with the cd command.

Command To Create a new batch file

Here you’ll come to know how to create a new batch file. Here we are creating a batch file. The batch file ends with .bat and helps to automate frequently used commands in the command line. Simply type edit example.bat at the prompt. If the edit command can’t work, use the start command to open the batch file in Notepad. Then input start notepad example.bat into the prompt.

Both of these commands open a new blank example.bat window. In the file, input the following commands, which clear the screen with the cls command and then execute the dir command.

@echo off
cls
dir

After you type these commands into the save, file, and exit the file. If you are in the edit command, tap File (or hit Alt+F) and then Save. When the file is saved and you are returned back into the command prompt, typing dir can show the example.bat in the abc directory.

You can now run the batch file to get a good understanding of what a batch file does. If you want to run the batch file type example at the prompt, which runs the batch file and clears the screen and then executes the dir command.

Command To Rename File

When the file is moved into the dir2 directory as mentioned above, you can then move into that directory with the cd command to rename the file. From the dir2 directory, use the rename command to rename the file into another name. Input rename example.bat first.bat at the prompt to rename the file to first.bat. Now after using the dir command, you should then view the first.bat as the only file.

Removing a file

You can remove or delete the file with the del command. Input del first.bat to remove the first.bat file. If successful, you are returned back to the prompt with no errors, and the dir command displays no files in the current directory.

Command to Rename a directory

Move back one directory to return back into the test directory after using cd.. command mentioned above. You can now rename the dir2 directory to something else using a similar rename command. At the prompt, input rename dir2 hope to rename the director. When this command is finished, input dir and you should now view one directory known as hope.

Removing a directory

If you want to remove hope directory you can then use the rmdir command. At the prompt, type rmdir hope to delete the hope directory.

List Available Commands

After getting a complete understanding of using the command line from the instructions mentioned above, you can head over to other available commands after typing help at the command line. Simply “help” provides you a listing of available commands with a complete description of every command.

Conclusion:

Here’s all about “Use Command Prompt To List Files”. Now you should have a complete understanding of how to navigate the command line, rename directories and files, create directories and files, and delete. As mentioned above, there are lots of other commands that can be used at the command line. For further queries and questions let us know in the comment section below!

Also Read:

About the author

Alex Joshua

Leave a Reply