Äquivalent des Unix-Suchbefehls unter Windows

Was entspricht dem Unix-Befehl find unter Windows?

Ich sehe, dass das find.exe unter Windows eher wie ein grep ist. Ich interessiere mich besonders für das Äquivalent von

find . -name [filename]
Author: Kevin Panko, 2012-03-16

7 answers

dir <drive: [drive:]> /s | findstr /i <pattern>

- alternative -

dir /s <drive:>\<pattern>

Beispiel

dir c: d: /s | findstr /i example.txt

- alternative -

dir /s c:\example.txt
 27
Author: JohannesM,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2012-06-25 12:19:34

Wenn keine zusätzlichen Cmdlets installiert sind, können Sie einfach Get-ChildItem:

Get-ChildItem -Filter *.zip -Recurse $pwd
 31
Author: djhaskin987,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2015-05-14 22:13:33

Das Cmdlet Find-ChildItem in Windows Powershell entspricht dem Befehl Unix / Linux find

Http://windows-powershell-scripts.blogspot.in/2009/08/unix-linux-find-equivalent-in.html

Einige Find-ChildItem Optionen

  1. Find-ChildItem -Type f -Name ".*.exe"
  2. Find-ChildItem -Type f -Name "\.c$" -Exec "Get-Content {} | Measure-Object -Line -Character -Word"
  3. Find-ChildItem -Type f -Empty
  4. Find-ChildItem -Type f -Empty -OutObject
  5. Find-ChildItem -Type f -Empty -Delete
  6. Find-ChildItem -Type f -Size +9M -Delete
  7. Find-ChildItem -Type d
  8. Find-ChildItem -Type f -Size +50m -WTime +5 -MaxDepth 1 -Delete

Disclosure: Ich bin der Entwickler von Find-ChildItem cmdlet

 28
Author: Jagadish G,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2015-02-03 08:03:18

Wenn Sie Unix ' s find verwenden, um nach Dateien in einer Verzeichnishierarchie zu suchen, dann die Powershell-Methode besteht darin, das Cmdlet Get-ChildItem (Alias ist gci) zu verwenden und die Ergebnisse mit dem Cmdlet Where-Object (Alias ist where) zu filtern.

Um beispielsweise alle Dateien (beginnend mit C:\Users\ und rekursiv) mit dem Wort "essential" im Namen zu finden, verwenden Sie Folgendes:
PS> gci -Path "C:\Users\"  -Recurse | where {$_.Name -like '*essential*'}

Mit der Option -like können Sie Platzhalter für den Mustervergleich verwenden.

 8
Author: Joshua Kan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2016-12-25 09:35:53

Dieser ist nicht gerade GNU find, aber entspricht genauer der Linux-Befehlszeile Philisophie unter Powershell:

PS> dir -recurse -ea 0 | % FullName | sls <grep_string>

Beispiel:

PS> cd C:\
PS> dir -recurse -ea 0 | % FullName | sls "Program" | sls "Microsoft"
PS> dir -recurse -ea 0 | % FullName | sls "Program" | sls "Microsoft" | out-gridview

Hinweis: Alles, was nach "| % FullName" zurückgegeben wird, ist eine Zeichenfolge anstelle eines Objekts.

Sie können auch den Where Operator verwenden,"?"es ist jedoch mehr Arbeit und nicht viel schneller:

PS> cd C:\
PS> dir -Recurse -ea 0 | ? FullName -like "*Program*" 
                       | ? FullName -like "*Microsoft*" 
                       | % FullName 
                       | out-gridview

Hier ist eine kurze Abkürzung:

PS> function myfind {dir -recurse -ea 0 | % FullName | sls $args }

PS> cd C:\
PS> myfind "Programs" | sls "Microsoft"

#find all text files recursively from current directory
PS> myfind "\.txt$"

#find all files recursively from current directory
PS> myfind .
 3
Author: Bill Moore,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2017-12-19 20:04:27
ls c:\ file.ext -r

Sie können diesen einfachen Powershell-Befehl verwenden. verwenden Sie-ErrorAction Ignore, um Berechtigungsfehler zu beseitigen.

 1
Author: Justin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2020-11-20 18:53:17

In PowerShell können Sie Get-ChildItem (auch bekannt als ls) verwenden, wie in anderen Antworten angegeben.

ls . -Filter *.zip -Recurse

Es kann auch nützlich sein, vollständige Dateipfade anstelle von Kurznamen abzurufen.

(ls -Path . -Filter *.zip -Recurse).FullName

Und Sie können auch einfach beliebige Befehle für die gefundenen Dateien ausführen.

(ls -Path . -Filter *.zip -Recurse).FullName | ForEach-Object -Process {
    # The $_ variable is the path to a located file.
    echo "Found file: $_"
}
 0
Author: Serid,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2021-02-02 00:29:23