OPERATING SYSTEMSOS Windows

Useful Commands to Manage Files and Folders using Command Prompt


This article lists down various commands that you can use to manage files and folders through Command-Line in Windows 10. Although a lot of users prefer using a graphical user interface to manage files for a hassle-free experience, some also use the command-line interface to perform file management tasks. In any case, it is always better to know alternative solutions to execute a task.

In this guide, I will be creating a list of useful commands that you can use for file or folder management on your Windows 10 PC. To perform a specific task on files or folders, there is a dedicated command that you need to enter in CMD. Let’s check out these commands!

Useful Commands to Manage Files and Folders through CMD in Windows 10

Commands to Manage Files and Folders through CMD

Here are the commands that you should know to manage files and folders using Command Prompt in Windows 10:

1] Create a File or Folder in CMD

To create a folder, type the folder name with the location where you want to create the folder. Here is the command:

mkdir <folder name with path>

For example;

mkdir C:UsersKOMALDocumentsTWC

To create a file of a specific size (in bytes), use the below command:

fsutil file createnew file.txt 4000

In place of file.txt, enter the filename with its extension and full path. And, 4000 is the file size in bytes.

2] Delete Files or Folder in CMD

You can remove a folder using the below command:

rmdir <folder name with path>

In order to delete a file, the command is:

del "<filename with path>"

If you want to delete all files from the current folder, enter the command:

del *

To delete files with a specific extension only, say png, use the command:

del *.png

If you want to delete files with a particular string in their filename, e.g., xyz, you can use the below command:

del *xyz*

3] Find Files in a Particular Folder

To find files inside a folder based on different parameters, you first need to navigate to the folder using the command:

cd "<folder name with location>"

Now, you can find files older than n days in a specific folder using the below command:

forfiles /s /m *.* /d -n /c "cmd /c echo @file

Replace -n with the number of days. Like if you want to find files older than 2 days, type -2.

To find files larger than a specific size, use the command:

forfiles /S /M * /C "cmd /c if @fsize GEQ 3741824 echo @path"

In the above command, 3741824 is the file size to search files greater than this size.

4] Rename all file extensions present in a folder at once

You can also batch rename file extensions in CMD. Suppose, you want to rename the file extension of all images to JPG, you can use the below command:

ren *.* *.jpg

5] Get File Creation Time and Date

To check the creation time and date of a specific file, use the command:

dir /T:C filename

6] Check for a string inside a file

To find all lines containing a particular string in a file, you can use the command:

findstr string file-name

For example, to display all lines with “twc” in a text file, you need to enter the command:

findstr twc twc.txt

Do remember that the above command is case-sensitive.

To find sentences with any specified string, use a command like:

findstr /C:"string1 string2 string3..." filename

7] Check for all Hidden Files in a Folder

Use the below command to get a list of hidden files in a directory:

dir /A:H /B

8] Compress a File in CMD

The command to compress a file in a folder is:

compact /c filename

9] Hide/ Unhide a file through CMD

To hide a file, the command used is:

attrib + h filename

You can unhide the file again using the command:

attrib -h filename

10] Set/ Unset Read-Only attribute to a file

To make a file read-only, the command is:

attrib +R filename

If you want to remove the read-only attribute from a file, the command is:

attrib -R filename

11] Command to Rename a File/Folder

rename oldfilename.pdf newfilename.pdf

12] Read File Content in CMD

You can read text file content in CMD using the below command:

more filename

13] Open a File in Default Application

You can open a file in its default application by entering a simple command:

"filename-with-path"

14] Move File / Folder to different Location

Suppose you want to move TWC12.pdf file to TWC folder in G drive, use below command:

move TWC12.pdf G:TWC

Command to move all files with a specific extension:

move *.png G:TWC

To move files starting with a particular letter, say A, command is:

move A* G:TWC

Similarly, you can move a folder using a command like below:

move foldername <new location>

For example:

move TWC1 G:TWC

15] Command to Copy Files

You can copy files from one location to another using command:

copy Sourcefolder DestinationFolder

Hope this article helps you learn some useful commands to manage files and folders through the command-line in Windows 10.

Useful Commands to Manage Files and Folders through CMD in Windows 10

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *