DOS equivalent to Unix command "find"?

I would like to be able to search for files on a Windows machine using DOS instead of the gui interface. For example, on Linux, I use:

to find. -name "* .c" -exec grep -Hn "sqlcommand" {} \;

Is there something similar with ms-dos?

Thanks.

+5
source share
3 answers

After a long time working with Unix systems, I had to make some scripts on Windows. For serious scripts, Powershell is the tool you should use. You can search the Internet with keywords such as powershell find string in file , or other combinations, and you will find a lot of information. What's the problem, simple oneliner like

 get-childitem C:\yourdir -include *.c -recursive |Select-String -pattern sqlcommand 

will not help you. You need to find the PowerShell IDE, learn the different syntax and try to love / accept new things.

Get ready to learn with PowerShell when you want to do this more often, or try to get a Unix-like environment on your windows (cygwin or better git for Windows).

+3
source

This requires a combination of two DOS commands:

  • FOR /F ["options"] %variable IN ('command') DO command [command-parameters]

    and

  • DIR /B /O:N /W *.c (this is the 'command' noted in the FOR command above)

Create a CMD script as follows:

 @ECHO OFF FOR /F %%B IN ('DIR /B /O:N /W *.cs') DO ( findstr /I /N /C:"sqlcommand" %%B ) 

OR , just use the find found in this set of Unix command ports:

http://unxutils.sourceforge.net/

or

http://sourceforge.net/projects/unxutils/

(both links must be of the same project)

+2
source

DOS has a FIND command, but it works a little differently than FIND in the Linux shell.

Syntax: FIND [/V] [/C] [/N] [/I] "string" [[drive:][path]filename[...]]

Where:

/V Displays all lines that do not contain the specified line.

/C Displays only the number of lines containing the line.

/N Displays line numbers with the displayed lines.

/I Ignores case of characters when searching for a string.

https://en.wikipedia.org/wiki/Find_%28command%29

+1
source

Source: https://habr.com/ru/post/1212642/


All Articles