20 Useful Windows Commands for managing files

Most people do not normally use command prompt commands in windows as they find it easy to use it as a graphic user interface. Using commands is not limited to linux. You can use beautiful commands for doing zillions of things and that too at a pretty fast rate. The capability of commands on command prompt is immense. Here in this article , i have listed some useful Commands of command prompt in windows Os.

Create New file

Step 1: – First of all go to the respective folder, in which you want to create the file.

Step 2: – Now, Press shift and do a right click anywhere.

Step 3: – Now, Click on Open command prompt window here.

open-cmd-here



Note: – This is the quickest method to browse to any directory and open command prompt right from there.

Step 4: – Now, write the following command given below to create the file here.

fsutil file createnew filename.txt 3000

Note that 3000 is file size in KB. You are also telling windows to create the file with that much required size. You can create any file type. Just give the required extension , name and file size.

create-file-cmd

Find files older than n days inside a folder

To find files older than 1 day, use command given below.

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

days-old-files

Find files modified in last n days

forfiles /P directory /S /D +(today'date - 10 days)

Find files larger than a specific size

You can run forfiles command in this case.

For example if you have to find files larger than 1 gb = 1073741824 bytes, the command would be as given below.

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

To find files larger than 1 MB use the given command.

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

forfiles

 

Rename all File extensions inside a folder at Once

Now, go to the folder where all the files are kept. Now, do a shift + right click to open command prompt there.

Now, just write the command given below to rename png to jpeg.

rename *.png*.jpeg

Note: – Just use any extensions in place of jpg and png above by replacing jpg and png with your required extensions.

The above command does not run recursively. It means , this command will not affect the files kept in subfolders.

To use it recursively use the given below command.

forfiles /S /M *.jpeg/C "cmd /c rename @file @fname.png"

 

In above command we are changing all files with .jpeg to .png .

recursively

Delete System Files in Windows

Who says you can’t delete system files. To delete system files:-



del /A:S systemfile.exe

Get File Creation Time and Date

Use the command given below to get the date and time when the file is created.

dir /T:C nameofthefile

file-creation-date-time

Find out a string inside a file

The command given below will fetch all lines and print them on screen having the word .

findstr string  file_name

For example if we have to find all lines containing windows in file.txt, then we will use command given below.

findstr windows file.txt

Note that, the above command is case sensitive. To do a case insensitive search add /I after the string.

findstr windows /I file.txt

You can also search for lines having any of the given strings.

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

Take ownership of a file

takeown /F fileName

Get the list of all hidden files inside a folder

To get the list of all hidden files and folders inside a directory use the given command.

dir /A:H /B

To get the full list of all hidden files / folders inside all sub-folders, use below given command.

dir /s /b /A:DH

Compress a File using command line

compact /c filename

 

Hide a file using Command line

attrib +s + h file_name

The file hidden by this method cannot be seen even with windows normal show hidden files and folder option method.

To unhide the file again, use: –

attrib -s -h file_name

Set Read Only attribute to a file

attrib +R file.doc

To remove read only attribute from the file again.

attrib -R file.doc

Delete a file in Windows Using CMD

For deleting the file Just go to the respective folder. do a shift + Right click and open command prompt window there.

Now use the command given below.

del filename.txt

To delete all the files in current folder

del *

To delete all the files with ‘.jpeg’ extension

del *.jpeg

To Delete all files having the ‘abc’ somewhere in file name

del *abc*

Rename a File Command

rename filename.txt newname.txt

Read File Command

Now, to read the contents of the file, just open command prompt at the location where the file is kept.



Now, just write the command given below.

more filename

read-file-cmd

Read last 10 or 20 Lines from a file

This Command will fetch last n lines from the file and display it on the command prompt window. You can read any number of lines from the file. Just replace 10 with any number.

tail -10 file.txt

Move File / Folder to another Location

In this move command is followed by filename and the destination in which you want to move the file.

move file.doc  d:\new\folder\

Move all files of a common extension to a new folder.

move *.txt  d:\new\folder\

Move all files starting with letter C.

move C* d:\new\folder\

Similarly you can move folders to a new location. Just use the folder name.

move data d:\backup\new folder

Copy files from one destination to another

To copy  all files inside a folder to another location

Xcopy /I Source_folder  Destination_folder

To copy all files and also sub-folders inside the folder as well.

Xcopy /S /I /E Source_folder Destination_folder

For example: –

Xcopy /S /I /E D:\backup\videos F:\new\media

You can also see more than 100 of useful run command shortcuts in windows