« ATM pin reversal scam | Main | Death threat, a new form of Nigerian Scam ? »

Convert Windows' dir /s to find format

hugh?
Sometimes some lazy or paranoid system administrator refuses to install the find command for Windows. So you are left only with the crappy Windows basic commands. You could reply of course that if they were so paranoid, they could download the source code, inspect it and recompile it themselves.

find is extremely useful to get a nice file tree that you can grep later from your Linux box (unless again you installed grep on Windows).

The Script
So when you don't have find and still need a basic find output eventually, you could use this script. It turns an output that looks like this:

 Volume in drive C has no label.
 Volume Serial Number is B0B8-957C

 Directory of C:\WINDOWS

12/19/2006 09:36 PM <DIR>        .
12/19/2006 09:36 PM <DIR>        ..
12/21/2006 03:44 PM            0 0.log
03/21/2006 11:01 AM <DIR>        addins
08/23/2001 08:00 PM        1,272 Blue Lace 16.bmp
08/23/2001 08:00 PM       82,944 clock.avi
08/23/2001 08:00 PM       17,062 Coffee Bean.bmp
12/19/2006 06:49 PM       43,027 comsetup.log
03/21/2006 11:01 AM <DIR>        Config
03/21/2006 11:01 AM <DIR>        Connection Wizard
03/21/2006 04:02 AM            0 control.ini
03/21/2006 03:55 AM <DIR>        Cursors
10/11/2006 05:43 PM <DIR>        Debug
...

Into an output that looks like this:

C:/WINDOWS
C:/WINDOWS/0.log
C:/WINDOWS/Blue Lace 16.bmp
C:/WINDOWS/clock.avi
C:/WINDOWS/Coffee Bean.bmp
C:/WINDOWS/control.ini
C:/WINDOWS/comsetup.log
C:/WINDOWS/addins
C:/WINDOWS/Config
C:/WINDOWS/Connection Wizard
C:/WINDOWS/Cursors
C:/WINDOWS/Debug
...

The script makes it easy to grep for particular files like .exe or .log or any other pattern that you may be looking for.

Native GNU tools on Windows
The better alternative of course is to install some vital GNU tools onto your Windows system.

Karl M. Syring has ported essential GNU tools to native Windows on his http://unxutils.sourceforge.net/ project.

' Here are some ports of common GNU utilities to native Win32. In this context, native means the executables do only depend on the Microsoft C-runtime (msvcrt.dll) and not an emulation layer like that provided by Cygwin tools. '

The tools included (at the time of this writing) are:

bc bison bzip2 diffutils
fileutils findutils flex gawk
grep gsar110 gzip indent
jwhois less m4 make
patch recode rman sed
shellutils tar textutils unrar
wget which

Emulated GNU tools on Windows
A team of enthusiasts originally from Cygnus (now part of RedHat) have created an emulation layer that allows to re-compile and run most GNU or standard Linux tools on Windows. You can download this environment called cygwin (in pre-compiled binary, or in source form).

' Cygwin is a Linux-like environment for Windows. It consists of two parts:

  • A DLL (cygwin1.dll) which acts as a Linux API emulation layer providing substantial Linux API functionality.
  • A collection of tools which provide Linux look and feel.

The Cygwin DLL works with all non-beta, non "release candidate", ix86 32 bit versions of Windows since Windows 95, with the exception of Windows CE. '

Cygwin contains an amazing number of GNU or Linux tools that come very handy on Windows, including mamoths like XWindow, XEmacs, openssh or ddd

Conclusion
In order of robustness & speed you should use:

  • the native version of find
  • or the cygwin version of find
  • or the script converting output from Windows' DIR /S into find format

June 2007

Sun Mon Tue Wed Thu Fri Sat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Professional IT Security Services:
FMA-RMS logo

Locations of visitors to this page