Linux find command for windows

What is the equivalent of the Unix find command on Windows?

I see that the find.exe on Windows is more like a grep. I am especially interested in the equivalent of

find . -name [filename]

Kevin Panko's user avatar

Kevin Panko

7,35622 gold badges44 silver badges53 bronze badges

asked Mar 16, 2012 at 15:10

ARV's user avatar

0

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

— alternative —

dir /s <drive:>\<pattern>

example

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

— alternative —

dir /s c:\example.txt

answered Mar 16, 2012 at 15:16

JohannesM's user avatar

JohannesMJohannesM

1,00011 silver badges17 bronze badges

5

With no additional cmdlets installed, you can simply use Get-ChildItem:

Get-ChildItem -Filter *.zip -Recurse $pwd

answered May 14, 2015 at 22:13

djhaskin987's user avatar

djhaskin987djhaskin987

4985 silver badges7 bronze badges

1

The Find-ChildItem Cmdlet in Windows Powershell is an equivalent of Unix/Linux find command

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

Some of Find-ChildItem Options

  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: I am the developer of Find-ChildItem cmdlet

answered Jun 25, 2012 at 8:32

Jagadish G's user avatar

Jagadish GJagadish G

4054 silver badges3 bronze badges

4

If you are using Unix’s find to search for files in a directory hierarchy, then
the Powershell way is to use Get-ChildItem (alias is gci) cmdlet and filter the results with the Where-Object (alias is where) cmdlet.

For example, to find all files (starting from C:\Users\ and recursively) with the word ‘essential’ in its name, use the following:

PS> gci -Path "C:\Users\"  -Recurse | where {$_.Name -like '*essential*'}

The -like option allows you to use wildcards for pattern matching.

Kamil Maciorowski's user avatar

answered Dec 25, 2016 at 8:47

Joshua Kan's user avatar

Joshua KanJoshua Kan

3073 silver badges6 bronze badges

This one is not exactly GNU find, but more closely matches the linux command line philisophy under powershell:

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

Example:

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

Note: Everything returned after «| % FullName» is a string, instead of an object.

You can also use the Where Operator, «?», however, its more work, and not much faster:

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

Here’s a quick shortcut:

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 .

answered Dec 19, 2017 at 19:28

Bill Moore's user avatar

Bill MooreBill Moore

2693 silver badges8 bronze badges

1

In PowerShell you can use Get-ChildItem (aka ls), as noted in other answers.

ls . -Filter *.zip -Recurse

It might also be useful to get full paths of files instead of short names.

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

And you can also easily execute arbitrary commands on the files found.

(ls -Path . -Filter *.zip -Recurse).FullName | ForEach-Object -Process {
    # The $_ variable is the path to a located file.
    echo "Found file: $_"
}

answered Feb 2, 2021 at 0:29

Serid's user avatar

SeridSerid

1334 bronze badges

1

ls c:\ file.ext -r

You can use this simple powershell command.
use -ErrorAction Ignore to get rid of permission errors.

answered Nov 19, 2020 at 1:13

Justin's user avatar

JustinJustin

1113 bronze badges

1

While not a full substitute, this simple batch file solved most of the problem for me:

# findw.bat
# 
# usage: findw dir search-pattern
#
dir %1 /s /b | findstr /i %2

answered Feb 27, 2021 at 20:49

sramam's user avatar

You can use get-childitem very similar to find.

get-childitem -recurse [startpath] -name [filetofind]

[startpath] is the path where recursion should begin (e.g. . for the current directory)

[filetofind] is what you are looking for.

It is even possible to do this from cmd (without interactieve powershell):

powershell -command "get-childitem -recurse [startpath] -name [filetofind]"

ZygD's user avatar

ZygD

2,45912 gold badges26 silver badges43 bronze badges

answered Dec 12, 2021 at 17:27

Anke's user avatar

You must log in to answer this question.

Not the answer you’re looking for? Browse other questions tagged

.

NEW AND IMPROVED ANSWER

I recently stumbled upon a built-in command that is rather similar to find in Unix:

ForFiles

Basic syntax is:

forfiles [/p <Path>] [/m <SearchMask>] [/s] [/c <Command>] [/d [{+|-}][{<Date>|<Days>}]]

There are several variables to use when constructing the command to execute per each file (via the /c switch):

  • @FILE File name.
  • @FNAME File name without extension.
  • @EXT File name extension.
  • @PATH Full path of the file.
  • @RELPATH Relative path of the file.
  • @ISDIR Evaluates to TRUE if a file type is a directory. Otherwise, this variable evaluates to FALSE.
  • @FSIZE File size, in bytes.
  • @FDATE Last modified date stamp on the file.
  • @FTIME Last modified time stamp on the file.

It looks like you would use the command like this:

FORFILES /m *.cs /c FINDSTR /I /N /C:"sqlcommand" @FILE

I’m not sure how long this command has been around, but the earliest reference I could find in the documentation is from 2008-09-02:

https://web.archive.org/web/20080902221744/http://technet.microsoft.com:80/en-us/library/cc753551.aspx

and that page states that it was last updated on «April 25, 2007». The documentation is filed under «Windows Server» so it likely started there and was added to the desktop OSes starting with Windows Vista, I believe. I did check Windows XP and didn’t see it there, though it is on Windows 10.


ORIGINAL ANSWER

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 command found in this set of Unix command ports:

http://unxutils.sourceforge.net/

or

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

(both links should be the same project)

on February 13, 2012

It’s very common scenario in IT field that people who are familiar with one OS have to learn/work with another OS. I do see many people, who are familiar with Linux commands, looking for their equivalent commands in Windows OS.  Below I have attempted to list down the Windows commands for most widely used Linux commands. If I have missed any, please write in the comments section and let me know.

Ls :       The Windows equivalent one is dir.  ‘Dir‘ has many  switches to list files based on different attributes, sort the list on size or date modified etc.

Grep : Findstr is the closet matching one for grep. find is also for searching strings in files, but it does not have many options.

Adduser:  We can use net user  to manage user accounts.

Useradd: net localgroup can be used to manage user groups. Net group can be used to manage active directory (domain) groups.

Uname  : ver command shows Windows OS version.  Systeminfo shows lot of hardware and software information.
Ps  : The closest matching command is tasklist, though it’s not as feature rich as ps.

Echo : echo. Very much similar to Linux’s echo.
Md :   mkdir

rm:     Del deletes files whereas  rmdir can be used to delete directories.
Du :    du can be used to monitor the disk usage.  However, this tool is not part of Windows OS. We need to install it separately. See the link for more information.
Df   :  Net use. We can list the network shares mapped on the computer.
Mount :    Net use . Map network share to local drive
Cat    :  Type  print the contents of a text file in the console/command prompt.
Head :   there’s no equivalent command I am aware of.
Tail   :   Tail resource kit tool.
touch: Fsutil can be used to create files of require size.

I will add few more commands to the list soon…If you are searching for some specific command and do not find it here, please let me know.

Last updated on 

Table of linux and windows commands equivalents like:

  • shutdown vs reboot
  • ipconfig vs ifconfig
  • F7 vs history
  • help vs man

Have you ever wonder about a command — is it a Linux one or a Windows one? For me, this happens all the time. I’m using commands quite often so I’ve made my own cheat-list with Linux and Windows pairs of commands. You can use it also when you want to learn the other operating system.
If you find any mistakes or incomplete information feel free to comment. I’m open for suggestions.

Note: It’s personal list based on personal experience. Some of the commands are used with different version of the OS so they could vary a little.

Next part is: Windows and Linux variable equivalents

Full page version:
Windows vs Linux commands cheat sheet

Here’s the result of it:

Windows

Linux

Type

Description

Command 

Example

Result

Command

Example

Result

General

Logoff

shutdown

shutdown -l

reboot

reboot

Restart

shutdown

shutdown -r

logout

logout

Shutdown

shutdown

shutdown -s

poweroff

poweroff

Show user

echo %USERNAME%

echo %USERNAME%

user

echo

echo $USER

user

Install application

apt-get
yum

sudo apt-get install ${package}
yum install ${package}

Remove application

apt-get
yum

apt-get remove ${package}
yum remove ${package}

Zip/unzip current folder

zip
unzip

zip -r file.zip folder
zip file.zip file
unzip -l file.zip

unzip

sudo apt-get install zip unzip
zip -r files.zip folder
zip files.zip file1 file2 file3
unzip /path/to/file.zip

Connect ssh

You need putty client

plink [email protected] -P 33

ssh

ssh [email protected]  -p 33

List mounted devices

net use

net use

findmnt

findmnt -lo source,target,fstype,label,options
-t ext4

Mount Remote

net use

net use \\Server\ShareFolder

mount

mount 192.168.1.1:/home /mnt/nfs/home

Show network info

ipconfig

ipconfig /all

Windows IP Configuration
   Host Name
   DNS Suffix Search List
Ethernet adapter Local Area Connection:
   Physical Address
   IPv4 Address
   Subnet Mask

ifconfig

ifconfig

eth0      Link encap:Ethernet  HWaddr
          inet addr:  Bcast:  Mask:
          inet6 addr: 
eth1      Link encap:Local  Hwaddr

Execute script

test.cmd

./

./test.sh

History

F7

F7

0: dir
1: cd ..
2: quser

history

history

 
1  ls
  2 
cd ..
  3 
pwd

Go to previous command

or F8

F8 or

Search for commands

CTRL+R

CTRL+R and type the command

Clears screen

cls

cls

clear

clear

Closes shell prompt

exit

exit

exit

Displays or sets date

date

date

date

Displays command help

command /?

dir /?

info

man command

Displays command help 2

help command

help dir

man

info command

Autocompletion

TAB

TAB

TAB

TAB

Uptime and logged user

quser

C:\Users\user\Desktop>quser

USERNAME;SESSIONNAME;ID;
STATE;IDLE;TIME;LOGON;TIME
>user;console;1;Active;none;
4/5/2016;8:48 AM

uptime

uptime

06:18:56 up 75 days, 17:31,  1 user, 
load average: 0.00, 0.00, 0.00

Files &
Folders

Show current folder

cd

cd

C:\Users\user

pwd

pwd

/home/user

Show current folder 2

chdir

chdir

C:\Users\user

echo

echo $PWD

/home/user

Create file

copy NUL file1.txt

touch

touch file.txt

Create file

echo. 2>file2.txt

cat

cat > myfile.txt

Renames a file

ren

ren file1.txt file2.txt

mv

mv tfileold.txt filenew.txt

Copies files

copy

copy file1.txt C:/foldercopy

cp

cp file.txt /home/foldercopy

Moves files

move

move file1.txt C:/newfolder

mv

mv file.txt /home/newfolder

Lists files

dir

ls

ls

Collect file names

dir

dir «C:\» >FilesC.txt /b /o

file1
file2

find

find /home -name ‘*’

/home/file1
/home/file2

Deletes files

del

del deleteme.txt

rm

rm deleteme.txt

Deletes folder

rmdir

rmdir /S deleteme

rm -r

rm -r deleteme

«Echoes» output to the
screen

echo

echo

echo this message

Delete file content

type
break

type nul
> file.txt
break>file.txt

cat

> file.txt
cat /dev/null > file.txt

Compares the contents of files

fc

fc file1.txt  file2.txt

Comparing files file1.txt and
file2.txt
***** file1.txt
1
***** file2.txt
2
*****

diff

diff file1.txt file2.txt

Finds a string of text in a file

find

find «test» 123.txt


———- 123.TXT
test

grep

grep test file1.txt

test line

Displays help

command /?

dir /?

info

man command

Displays help 2

help command

help dir

man

info command

Creates a folder

mkdir

mkdir newfolder

mkdir

mkdir directory

View file content

more

more file1.txt

less

less file1.txt

View file content 2

type

type file1.txt

tail

tail -n 15 file1.txt

Edit file

edit

edit  file1.txt

vi
nano
gedit

vi file.txt
nano 
file.txt
gedit 
file.txt

Changes directories with a
specified path (absolute path)

cd

cd C:/

cd

cd /directory/directory

Go one folder

cd

cd ..

cd

cd ..

Search for a file

dir

dir /s *test*

07/31/2010  02:30 AM               301 test.png
               1 File(s)            301 bytes

find

find / -name ‘*test*’

/home/test.txt
/home/file2.png

Search for text files

dir

dir /b/s *.txt 

find

find / -name ‘*.txt’

Change files extension to lower

ren

ren *.TXT *.txt

mv

 for i in $( ls
*.TXT ); do echo $i; mv $i  ${i%%.TXT}.txt;
done

Check files permissions

ls

ls -l /home/user

«-rwxrxr-x 1 root root  53 Mar 23 
2015 /home/user»

Change Permissions

chmod

chmod 755 file

Changing ownership

chown

chown user file

Changing group ownership

chgrp

chgrp group file

Other

Displays the date

date

date /T

Wed 07/05/2017

date

date ‘+%d %W %Y’
date ‘+%D’

05 27 2017
05/27/2017

Displays the time

time

time /T

1:27 PM

date

date ‘+%X’

12:18:22 PM

Shows amount of RAM in use

wmic

wmic OS get FreePhysicalMemory
/Value

free

free

Show disk space

wmic

wmic logicaldisk
get size,freespace,caption

dh

dh -f

Show processes

tasklist

tasklist

top

top

Services

Stop execution

CTRL+C

CTRL+C

CTRL+C

CTRL+C

Start service

net

net start [serviceName]

service

sudo service [serviceName] start

Stop service

net

net stop [serviceName]

service

sudo service [serviceName] stop

Start service 2

sc

sc start [serviceName]

systemctl

sudo systemctl start [serviceName]

Stop service 2

sc

sc stop [serviceName]

systemctl

sudo systemctl stop [serviceName]

Variables

Display all variables

set

set

USERNAME=user
USERPROFILE=C:\Users\user
windir=C:\Windows

printenv

printenv

HOME=/home/user
LOGNAME=user

Display variable

echo

echo %USERNAME%

user

echo

echo $HOME

/home/user

Display variable 2

set

set USERNAME

USERNAME=user

printenv

printenv | grep

HOME=/home/user

Set variable

set

set MYVAR=VALUE

export

export MYVAR=/path/to/var

Set variable permanent

setx

setx MYVAR VALUE

change profile

vi ~/.bash_proflle
export MYVAR=/path/to/var

Linux provides the find command in order to find files and directories. The find command is executed via the command line interface and it is also provided by the Unix and other related Unix-based operating systems. The find command can be used to search files and folders according to their names, creation date, modification date, ownership, permission, path, etc. Also, it provides useful features like executing commands for the match results.

find Command Syntax

The find command has the following syntax.

find PATH -name SEARCH_TERM OPTIONS
  • PATH is the search path where the specified SEARCH_TERM will be searched.
  • SEARCH_TERM is searched in the specified PATH.
  • OPTIONS are used for different search types. The option can e used to search for a specific file name pattern or file extension or recursively etc.

The find command provides different help options where the --help option is one of them. The –help option list very basic help and usage information about the find command.

$ find --help

To get more details about the find command the man page can be used. The man page of the find command provides a lot of information about the options, usage examples, etc.

$ man find

Search File with Name

The files can be searched according to their names by using the -name option. The complete or partial name is provided as a parameter with the -name option. In the following example, we search for the file named “database” in the home directory of the user “ismail”.

$ find /home/ismail -name database

Alternatively, we can search in the current working directory and all child directories by using bash “.” operator.

$ find . -name database

Search File with Pattern

The find command provides the ability to search files with their names for specific patterns. The “*” glob operator can be used to search files with partial names. We can search files those names that contain “data” with the following command.

$ find / -name "*data*"

Search File with Extension

The find command can be used to search files according to their extensions. The glob operator is used to express the name of the file and the extension is specified explicitly. In the following example, we search files with the “*.txt” extension.

$ find / -name "*.txt*"

Find and Delete File

One of the useful features of the find command is the ability to delete founded files. The -exec option is used to delete files by executing the “rm” command. In the following example, we delete all text or “*.txt” extension files.

$ find / -name "*.txt*" -exec rm {} \;

Search Empty Files and Directory

The Linux operating system may contain empty files and directories. The find command can be used to find empty files and directories easily by using the -empty option. There is no need to provide a file or directory name.

$ find / -empty

Search Empty Files with Specific Extension

The -empty option can be used to search empty files with a specific extension. In the following example, we search empty *.txt files by using the -name option.

$ find / -name "*.txt" -empty

Search with Permission

Another useful feature of the find command is the ability to search files and directories according to their permissions. The Linux system use permission consisting of 3 numbers like “000”, “777” etc. The -perm the option is used to specify the permission value where all matched files and directories will be listed.

$ find / -perm 777

Search SUID Enabled Files

The find command can be used to search SUID-enabled files. SUID is a permission that enables the normal user to run privileged commands on its own. The -perm option is used to specify SUID with /u=s parameters.

$ find / -perm /u=s

Even we can search and delete SUID-enabled bash scripts for the specified path and all of its children.

$ find /tmp -perm /u=s -exec rm {} \;

Search with User Name

In Linux, every file and directory has an owner. The find command can be used to search according to the owner information of the file or directory. The -user option is used to specify the owner name of the file or directory. In the following example, we search files and directories owned by “ismail”.

$ find / -user "ismail"

Search with Size

Another interesting option for the find command is the ability to search for the size of the files. The -size option can be used to specify search terms that specified the size of the files to match. In the following example, we search for files with 100M size.

$ find / -size 100M

In the following example, we search for the files whose sizes are higher than 100M.

$ find / -size +100M

In the following example, we search for the files whose sizes are lower than 100M.

$ find / -size -100M

In the following example, we will search files with sizes between 100M and 200M.

$ find / -size +100M -size -200M

Delete Matched Files

The find command provides the ability to execute commands using the matched file names. The -exec option is used to run commands and scripts where the matched filename is expressed with the {} . In the following example, we run rm command for every matched file by the find command.

$ find / -t f -name *.tmp -exe rm {} \;

Windows find Command

The counterpart operating system Windows also provides the find command but it is very weak with its features and does not provide the same functionality Linux find command. The Windows find command can be used for basic search operations by providing the search term and search path like below.

> find /V "ismail" C:\

  • Linkedin windows 10 что это
  • Linux mint rdp to windows
  • Link to windows samsung что это
  • Linux make bootable windows usb
  • Lim stickers скачать бесплатно для windows 10