Quick Find files under Windows command Line (CMD) (similar to the Linux find command)

Source: Internet
Author: User

Introduction to FOR/R Usage

Using the Find command under Linux, found it convenient to find files, then there are no similar commands under Windows can traverse the directory and find the file by file name? The answer is:

Commands under Windows for /r have features similar to those under the Linux find command, using syntax similar to the following:

find /r 目录名 %变量名 in (匹配模式1,匹配模式2) do 命令

The matching pattern can be a wildcard similar to:

    • *.jpg: All files of the. jpg suffix
    • *test*: All files with the test in the name

Attention:
1. Take at least 1 * numbers in the matching mode
2. Match content is limited to file name, does not match directory name

If only the lookup and output file names are available, the command behind do can be used @echo %变量名 , i.e.:

for /r 目录名 %i in (匹配模式1,匹配模式2) do @echo %i
Examples of common use:
# List all the files in the TestDir directory and all subdirectoriesC:\users\cashey\desktop> for/R TestDir%iinch(*) Do@Echo%ic:\users\cashey\desktop\testdir\b.jpgc:\users\cashey\desktop\testdir\c.pngc:\users\cashey\desktop\testdir\ Doc\1. txtc:\users\cashey\desktop\testdir\doc\2. txtc:\users\cashey\desktop\testdir\src\test.py# Find all txt files in the TestDir directory and all subdirectoriesC:\users\cashey\desktop> for/R TestDir%iinch(*.txt) Do@Echo%ic:\users\cashey\desktop\testdir\doc\1. txtc:\users\cashey\desktop\testdir\doc\2. txt# Find all txt and jpg files in the TestDir directory and all subdirectoriesC:\users\cashey\desktop> for/R TestDir%iinch(*.txt,*.jpg) Do@Echo%ic:\users\cashey\desktop\testdir\b.jpgc:\users\cashey\desktop\testdir\doc\1. txtc:\users\cashey\desktop\testdir\doc\2. txt# Find all files in the TestDir directory and all subdirectories that contain the test file nameC:\users\cashey\desktop> for/R TestDir%iinch(*test*) Do@Echo%ic:\users\cashey\desktop\testdir\src\test.py
Points to be aware of

If the match pattern does not take the * number and does not exactly match the file name, the result of the matching pattern is printed on all subdirectories, as follows:

# # 目录中事实上不包含任何名称为abc的文件C:\Users\cashey\Desktop>forindo @echo %iC:\Users\cashey\Desktop\TestDir\abcC:\Users\cashey\Desktop\TestDir\doc\abcC:\Users\cashey\Desktop\TestDir\src\abc

The above output is generally not expected, you need to take at least 1 * numbers in the pattern

Quick Find files under Windows command Line (CMD) (similar to the Linux find command)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.