Wednesday, August 11, 2010

How to find files in Ms Windows using command line

dir c:\Local\Data\xxx\ /s /b | find "string"

Find
http://technet.microsoft.com/en-us/library/cc725655%28WS.10%29.aspx

Dir
http://technet.microsoft.com/en-us/library/cc755121%28WS.10%29.aspx

Examples

To display all lines from Pencil.ad that contain the string "Pencil Sharpener", type:

find "Pencil Sharpener" pencil.ad


To find a string that contains text within quotation marks, you must enclose the entire string in quotation marks. Then you must use two quotation marks for each quotation mark contained within the string. To find "The scientists labeled their paper "for discussion only." It is not a final report." in Report.doc, type:

find "The scientists labeled their paper ""for discussion only."" It is not a final report." report.doc


If you want to search for a set of files, you can use the find command within the for command. To search the current directory for files that have the extension .bat and that contain the string "PROMPT", type:

for %f in (*.bat) do find "PROMPT" %f 


To search your hard disk to find and display the file names on drive C that contain the string "CPU", use the pipe (|) to direct the output of the dir command to the find command as follows:

dir c:\ /s /b | find "CPU" 


Because find searches are case-sensitive and dir produces uppercase output, you must either type the string "CPU" in uppercase letters or use the /i command-line option with find.

No comments:

Post a Comment

Related post:

Related Posts with Thumbnails