UnixDos,Toolkit,utilities,file,management,administration,command,line,process,control,batch,UNIX,Windows95,WindowsNT,UnixDos,Toolkit,conversion,edit,manipulation,search,directory,count,extract,sort,split,compare,merge,test,interaction,MSDOS,DOS,32bit,16bit,grep, ls, du, df, find, mv, rm, m4,chmod, cc, dd, cmpdir, cut, cpio, expr, head, tail, fgrep, egrep, mkdir, mvdir, nl, paste, pr, od, rm, sed, sleep, split, sum, strings, tee, touch, date, echo, join, more, uniq, sort, uptime, uudecode, uuencode, wc, which,sharewareExamples how to use UnixDosud_lo.gif (12165 bytes)

UnixDos,Toolkit,utilities,file,management,administration,command,line,process,control,batch,UNIX,Windows95,WindowsNT,UnixDos,Toolkit,conversion,edit,manipulation,search,directory,count,extract,sort,split,compare,merge,test,interaction,MSDOS,DOS,32bit,16bit,grep, ls, du, df, find, mv, rm, m4,chmod, cc, dd, cmpdir, cut, cpio, expr, head, tail, fgrep, egrep, mkdir, mvdir, nl, paste, pr, od, rm, sed, sleep, split, sum, strings, tee, touch, date, echo, join, more, uniq, sort, uptime, uudecode, uuencode, wc, which,sharewareHere are some tips how some of the powerful UnixDos utilities can be applied:


In the section below we will present several practical and useful examples how to apply the powerful UnixDos utilities.

1: Get a quick overview of free space on ALL your drives

Often you need to know where you have the biggest free space or how much the capacity of
all your drives are. Use the following command:

df -a

The output might look like:

C:(C_900MB             )  55,115,776 free (   901,857,280 total) 6.1% free
D:(D_512MB             )  55,508,992 free (   536,428,544 total) 10.3% free
E:(E_400MB             )  37,601,280 free (   433,258,496 total) 8.7% free
F:(F_512MB             )  25,018,368 free (   536,428,544 total) 4.7% free
G:(F_1GB_MUSIC         ) 270,696,448 free ( 1,053,999,104 total) 25.7% free
L:(COREL_345           )           0 free (   526,319,616 total) 0.0% free
===============================================================================
  (*** GRAND TOTAL *** ) 443,940,864 free ( 3,988,291,584 total) 11.1% free

To exclude the CD-ROM on drive L: use:

df C d e f g

C:(C_900MB             )  55,115,776 free (   901,857,280 total) 6.1% free
D:(D_512MB             )  55,508,992 free (   536,428,544 total) 10.3% free
E:(E_400MB             )  37,601,280 free (   433,258,496 total) 8.7% free
F:(F_512MB             )  25,018,368 free (   536,428,544 total) 4.7% free
G:(F_1GB_MUSIC         ) 270,696,448 free ( 1,053,999,104 total) 25.7% free
===============================================================================
  (*** GRAND TOTAL *** ) 443,940,864 free ( 3,461,971,968 total) 12.8% free

2: Find space hogs (Hit list of large files sorted by size)

Many times you might get tight on disk space and want to know where all the space goes.

The following command will search for the 20 biggest files on drive C D and E:

du -h10 C: D: E:

The output might look like:

List of the 10 largest files sorted by size in descending order:
-----------------------------------------------------------------
20,322,482 e:/MSVC/HELP/VCBKS15.HLP
16,610,031 e:/MSVC/HELP/VCSDK15.HLP
15,581,184 e:/MSVC/HELP/VCBKS15.HLP
11,090,254 e:/WINDEV/WINDEV.ZIP
10,919,006 e:/PMW/PMW.WRK
7,245,478 e:/DRG/MSDNCD15.IDX
4,325,728 e:/MSOFFICE/ACCESS/MSACC20.HLP
4,246,784 e:/MSOFFICE/EXCEL/EXCEL.EXE
3,490,816 e:/MSOFFICE/WINWORD/WINWORD.EXE
3,390,373 e:/VB30/WINAPI/WIN31WH.HLP

As an alternative you can search for all the files which are larger than a certain specified size.
The following command will search the entire current hard disk C: D: and directory E:\TMP and show you very quickly all the files which are larger than one megabyte (1,000,000 bytes):

ufind C: D: E:/tmp -size +1m -ls                  or
ufind C: D: E:/tmp -size +1000000c -ls

The output might look like:

-rw-rw-rw- 41943040 Aug 22 00:12 c:/PAGEFILE.SYS
-rw-rw-rw- 10485760 Aug 22 16:27 c:/WIN95/WIN386.SWP
-rw-rw-rw- 99999744 Aug 06 12:29 d:/BOOKS/DATABASE/ODD.NFO
-rw-rw-rw- 94371840 Aug 22 00:12 d:/PAGEFILE.SYS
-rw-rw-rw- 11249352 Aug 10 11:20 d:/PARK/ACC_NIR.ZIP
-rw-rw-rw- 23705165 Aug 22 14:34 d:/PARK/ud_all.zip
-rw-rw-rw- 35443990 Aug 22 00:59 d:/PARK/win95.zip
-rw-rw-rw- 11386604 Dec 04 1996 d:/PARK/WW32_302.ZIP
-rw-rw-rw- 32099034 Nov 29 1996 d:/PARK_FIX/MSOFFICE.ZIP
-r--r--r-- 55871814 Jun 06 1996 d:/PARK_FIX/NT351_0.Z
-rw-rw-rw- 12244344 May 27 1996 d:/PARK_FIX/VB40.ZIP

You can customize the threshold size we used here (-1m): 1,000,000 bytes.

3: Keep daily version of a (backup) file

As a daily routine you (hopefully) create a backup file (for example a. ZIP file).
To keep earlier versions you would have to manually copy to a new name every day:
ren myfiles.zip myfiles_Nov12_97.zip

The following UnixDos batch file will automatize exactly this repetitive task for you:
@echo off
rem ****** DEFINE THE FILENAME ****************************
set FILE=/tmp/myfiles.zip

rem ****** USE THE FIRST ARGUMENT INSTEAD OF A FIXED NAME *****
rem set FILE=%1

rem ****** CREATE THE TEXTUAL TIMESTAMP ********
udate "+
%%h%%d_%%y%%n" > now.tmp

rem ****** GET THE FILE ELEMENTS ********
extname $FILE > ext.tmp
filename $FILE > name.tmp
dirname $FILE > dir.tmp

rem ****** GET THE FILE ELEMENTS ********
uecho @dir.tmp "/" @name.tmp @now.tmp "." @ext.tmp | sed "s: ::g" > new.tmp
cp -lv $FILE @new.tmp

The output might look like:
/tmp/myfiles.zip -> /tmp/myfiles_Nov25_97.zip
1 files written successfully

You can specify any kind of date and time related format using the UDATE "+format" method.

4: Custom process each files in a list
(i.e. replace something in each file)

In this example we demonstrate how to process each line in a file list.
This example will first make a list of all your files in the current directory and then show you each name.
You can insert your custom process to apply to each file in the list
(i.e to replace use: sed "s:old:new:g" %NAME% > x1.tmp  AND mv -lvf x1.tmp %NAME%)

The following script will get one line at a time until the file is exhausted (see test_lst.bat):

@echo off
set LINE=3
set LST=files.lst
rem ****** FILL THE FILES LIST ******
ls > files.lst
:LOOP
    rem ****** EXTRACT THE NEXT LINE ******
    getlines %LINE% %LINE% %LST% > name.tmp
    if errorlevel 1 goto END

    rem ****** SET AN ENV VARIABLE WITH THE CURRENT FILE NAME ****
    call setenv "NAME=@name.tmp"

    rem ****** HERE YOU CAN PLACE YOUR CUSTOM PROCESS ******
    echo %LST% LINE %LINE% = %NAME%
    rem ****** EXAMPLE FOR REPLACING old WITH new ******
    rem sed "s:old:new:g" %NAME% > new.tmp
    rem mv -lvf new.tmp %NAME%

    rem ****** INCREMENT THE LINE NUMBER ENV VARIABLE ******
    call setenv "LINE=`expr $LINE + 1`"
goto LOOP
:END
del name.tmp

Might show something like:

files.lst  LINE 1 = autoexec.bat
files.lst  LINE 2 = command.com
files.lst  LINE 3 = config.sys
files.lst  LINE 4 = pagefiles.sys
files.lst  LINE 5 = windows

...

5: Find a text document anywhere on your machine using a text search

In some cases when you have many documents(*.doc, *.txt etc) across many different directories you might forget where a particular document resides. With the following command you can easily find the document if you remember at least one fairly unique text string within that document (the case doesn't matter -i option)

c:
cd \
grep -d -l -s -i mystring *.doc *.rtf *.txt *.hlp *.wri

This will find "MyString" or "myString" or "MYSTRING" since the "-i" option will ignore the case. Option -d descends, option ī-lījust lists the file, option -s skips the error messages.

Example:

c:
cd \
grep -d -l -s -i mystring"unixdos license" *.doc *.rtf *.txt *.hlp *.wri

Might show:
ud/help/ud_gen.rtf
ud/help/ud_lic.rtf
ud/help/ud_tips.rtf
ud/help/unixdos.hlp
Unixdos/unixdos.hlp

The "cannot open" message simply indicate that GREP did not find any of these files in the root directory -
nothing to worry about!



6: Get used Disk Space and Directory Overview

Sometimes you need to "step back" and get an overview of all the directories on your hard disk. The following command will produce a list of all the directories in alphabetical order and store it in a text file "all.du" in the root directory:

c:
cd \
du -o / > all.du

The output in 'all.du' might look like:

Megabytes (Cluster = 8192 bytes)
  5.6033 f:/Acrobat
  0.0082 f:/AOL30
  5.9228 f:/aolpress
  9.6911 f:/BITWARE
  0.0492 f:/DIGIDEMO
  0.0164 f:/ETC
  0.3441 f:/FTP
 31.3262 f:/instshld
  3.9895 f:/JAMWIN
217.3419 f:/MSDEV
 18.4566 f:/MSVC32S
  6.5536 f:/PBWIN
  2.6214 f:/PMAIL
  3.9485 f:/PMAIL250
  2.6214 f:/RCDPC30
  0.0737 f:/RECYCLED
  ----   f:/TMP
  0.0328 f:/TYPESET
  4.5957 f:/VENTURA
 30.6954 f:/VisualCafe
126.5009 f:/WIN311
  0.7373 f:/WS_FTP
  2.0480 f:/{Files}
511.2955 f:/

Note that empty directories are show as '---' and in the overview mode DU will only show the directory totals, but not all the sub directories.

To see the sub directories use DU without the Overview option (-o):

du f:\aolpress

The output might look like:

Megabytes (Cluster = 8192 bytes)
0.0082 f:/aolpress/AutoSave
1.3517 f:/aolpress/HELP/refer
0.9011 f:/aolpress/HELP/TUTORIAL
2.4330 f:/aolpress/HELP
0.0082 f:/aolpress/npcache
5.9228 f:/aolpress

7: Cleanup temporary files

As a daily routine you might want to remove all the temporary files on your machine (over night for example). Temporary files usually have the `*.tmp' file extension and reside in certain directories.

We will use the UFIND utility and execute RM for each temporary file found:

ufind / -name '*.tmp' -exec rm -lf {} ; or
ufind / -name '*.tmp' -exec rm -lf {} ^

I have also the habit of naming all my temporary work files starting with "xx", to also clean them up I use:

ufind / -name '*/xx*' -exec rm -lf {} ^

Here is a batch file which also cleans up the temporary directories::

@echo off
c:
cd \
rm -rfl "\win95\temp\*"
rm -rfl "\win95\Temporary Internet Files\*"
rm -fl "\tmp\*"
rm -fl "\temp\*"
rm -rfl "\recycled\*"
ufind / -name '*.tmp' -exec rm -l {} ;

8: Find all files you worked on today

Sometimes will want to get a list of files you worked on today. First we have to create a reference file of midnight of the current day and the do the search.
In this example we are searching he drives C:/D:/E:/F: - so you just replace this list with your list of drives.

The following batch file will do the job:

@echo off
rem ****** DEFINE THE REFERENCE FILENAME ******
set REF_FILE=c:\today.ref

rem ****** CREATE THE REFERENCE FILE ******
udate +%%m%%d%%n | sed "s:$:0000:" > today.tmp
touch @today.tmp %REF_FILE%
rm today.tmp
ls -l %REF_FILE%

rem ****** DO THE SEARCH ******
uecho Searching files worked on today ...
ufind c: d: e: f: -newer %REF_FILE% -ls > today.lst

rem ****** SHOW THE RESULT ******
umore today.lst

If you just want to see all the files you worked on within the last 24 hours use directly UFIND:

ufind c: d: e: f: -mtime 24h -ls

9: Finding duplicate files on your machine

Often you will find many duplicate or identical files on your machine stored in different directories.
This takes up extra space and can be problematic if you have the same two or more versions of the same program name stored in different directories since it will be accidental which program is called depending on the PATH and the current directory.

UnixDos offers a simple way to get a list of all the duplicate files on your machine.

The following batch file will do the job:

@echo off
rem **** GET ALL FILES ****
set LINE=1
set LST=work5.tmp
set OUT=files.dup
uecho Collecting all names ...
ufind c:/ d:/ -keyname: -ls > work1.tmp
uecho Found "`wc -lt work1.tmp # cut -f1`" Files ...

rem **** SORT ALL FILES ****
uecho Sorting all names ...
usort work1.tmp -o work2.tmp
usort -u +0 -1 -t: work2.tmp -o work3.tmp
uecho Finding Duplicates ...

rem **** FIND DUPLICATES ****
diff -c1 work2.tmp work3.tmp > work4.tmp
grep "^+" work4.tmp | cut "-d|" -f2 | cut -f1 -d: > %LST%
wc -lt %LST% | cut -f1 > work7.tmp
uecho Found "@work7.tmp" duplicates ...

rem **** GENERATE OUTPUT ****
rm -rf %OUT%
uecho Generating output in %OUT% ...

:LOOP
    getlines %LINE% %LINE% %LST% > name.tmp
    if errorlevel 1 goto END


          rem **** SHOW PROGRESS ****
        call setenv "NAME=@name.tmp"
    uecho -e %LINE% of "@work7.tmp" : %NAME%
    uecho "=====================================" >> %OUT%

    rem **** EXTRACT DUPLICATES ****
    sed "s:\.:\\.:g" name.tmp > work6.tmp
    sed "s:\$:\\$:g" work6.tmp > name.tmp
    sed "s:^:^:" name.tmp > work6.tmp
    sed "s/$/:/" work6.tmp > name.tmp
    grep "@name.tmp" work2.tmp >> %OUT%

    call setenv "LINE=`expr $LINE + 1`"
    goto LOOP
:END
uecho "=====================================" >> %OUT%

rem **** CLEANUP AND DISPLAY RESULT ****
rm work*.tmp
umore %OUT%

If you want to narrow the search only to executable (*.exe) files use:
ufind c:/ d:/ -name ‘*.exe’ -keyname: -ls > work1.tmp

To get simply a sorted  list by the filename enter:

ufind c:/ -keyname: -ls > all.lst
usort all.lst -o all.lst

10: Measure elapsed Time for (batch) process

Sometimes you might want to know how long a process or a batch of processes take.

The following command will reset the starting time:
uptime -i

Then you can do your processing.
call proc.bat

To get the elapsed time enter:
uptime

And it will display something like
00:00:20 elapsed since reboot at:
Fri Oct 25 11:02:56 1996

This means 20 seconds since the last  "uptime -i":

11: Find the main directories from the root directory

To find all the main directories in your root directory enter:
c:
cd \
ls -p | grep "/"

Might display:
/dos622
/msoffice
/Program Files
/SC
/windows

So see also how much space each major branch on drive C: and E: is using enter:
du -o C: E:

To find all the main directories with one level deep subdirectories in your root directory enter:
ufind c: -type d -level 2 -print

Might display:
c:/DOS622
c:/MSOFFICE/ACCESS
c:/MSOFFICE/CLIPART
c:/MSOFFICE/EXCEL
c:/MSOFFICE/POWERPNT
c:/MSOFFICE/SETUP
c:/MSOFFICE/WINWORD
c:/MSOFFICE
c:/Program Files/Accessories
c:/Program Files/Borland
c:/Program Files/Common Files
c:/Program Files/ICW-Internet Connection Wizard
c:/Program Files/Internet Explorer
c:/Program Files/Microsoft Exchange
c:/Program Files/Microsoft Internet
c:/Program Files/Symantec
c:/Program Files/The Microsoft Network
c:/Program Files
c:/SC/MSDOS6.22
c:/SC/WIN95
c:/SC/WIN_NT
c:/SC
c:/WINDOWS/Java
c:/WINDOWS/MSAPPS
c:/WINDOWS/MSSETUP
c:/WINDOWS/OLD
c:/WINDOWS/PFM
c:/WINDOWS/REPAIR
c:/WINDOWS/SYSTEM
c:/WINDOWS/SYSTEM32
c:/WINDOWS/UNINSTAL
c:/WINDOWS/VGAUTIL
c:/WINDOWS
c:/

12: List several numbers (or names) on one single line

In some cases you might have a text file containing a number or short text on each line. Now when you print this file you would waste a lot of space since you only place one item on each line while you could have much more (like 10) per line.

The following PASTE command will string five items per line:

paste - - - - - < list.txt

Might show:
181   300   97 2142  221
267   234  288  190  117
33    195  263  295 1617
1547  627  284  605  426
1013   94   74  273  569
129   610  569  783    1
918   832  454  811  130
210   145   86 1194

If "list.txt" contained:
181
300
97
2142
221
267
234
288
190
117
33
195
263
295
1617
1547
627
284
605
426
1013
94
74
273
569
129
610
569
783
1
918
832
454
811
130
210
145
86
1194

13: User Prompt Example

The following batch file shows several examples how to prompt the user for input:

Prompt the user for the files to copy with checks (see test_cp.bat):

@echo off
rem ****** CHECK IF COPY WANTED **************************
usrchar Do you want to copy a file? (Y/N)\c yn
IF ERRORLEVEL 2 GOTO END

rem ****** GET THE INPUT FILENAME ************************
usrprmpt Enter the source filename:\c -r
call setenv "IN=@usrprmpt.tmp"

rem ****** CHECK IF THIS FILE EXISTS *********************
test -r "$IN" runneg: echo FILE %IN% DOES NOT EXIST
IF ERRORLEVEL 1 GOTO END

rem ****** GET THE OUTPUT FILENAME ***********************
echo Enter the destination filename:
call setenv "OUT=`line`"

rem ****** CHECK IF IT IS WRITABLE IF IT EXISTS **********
test -r $OUT
IF ERRORLEVEL 1 GOTO DO_COPY
test -w $OUT runneg: echo CANNOT WRITE TO FILE %OUT%
IF ERRORLEVEL 1 GOTO END

rem ****** EXECUTE THE ACTUAL COPY ***********************
:DO_COPY
cp -l %IN% %OUT%
goto END

:END

Output example1:

Do you want to copy a file? (Y/N) Y
Enter the source filename: blabla
FILE blabla DOES NOT EXIST

Output example2:

Do you want to copy a file? (Y/N) Y
Enter the source filename: x1.bat
Enter the destination filename:
xnew
CANNOT WRITE TO FILE xnew

Output example3:

Do you want to copy a file? (Y/N) Y
Enter the source filename: x1.bat
Enter the destination filename:
newfile
x1.bat -> newfile
1 files written successfully

14: Loop Example

In this example we demonstrate how to write a simple loop in a batch file.
We will print a table of the powers of two (see test_exp.bat):

@echo off
set EXP=1
set BASE=2
:LOOP
echo 2 power %EXP% = %BASE%
call setenv "EXP=`expr $EXP + 1`"
call setenv "BASE=`expr $BASE x 2`"
test $EXP -le 16
IF NOT ERRORLEVEL 1 GOTO LOOP

Will print:

2 power 1 = 2
2 power 2 = 4
2 power 3 = 8
2 power 4 = 16
2 power 5 = 32
2 power 6 = 64
2 power 7 = 128
2 power 8 = 256
2 power 9 = 512
2 power 10 = 1024
2 power 11 = 2048
2 power 12 = 4096
2 power 13 = 8192
2 power 14 = 16384
2 power 15 = 32768
2 power 16 = 65536
2 power 17 = 131072
2 power 18 = 262144
2 power 19 = 524288
2 power 20 = 1048576
2 power 21 = 2097152
2 power 22 = 4194304
2 power 23 = 8388608
2 power 24 = 16777216
2 power 25 = 33554432
2 power 26 = 67108864
2 power 27 = 134217728
2 power 28 = 268435456
2 power 29 = 536870912
2 power 30 = 1073741824

15: View many small files together (i.e. all your batch files)

If you have many small files and want to print them you can either print one page per file or concatenate all files into one file, but loose the filename.

If you could insert in front of each line the filename you could easily find any information in one file.

In the following example we create a list of files of your zip files in files with extension *.zls.
This assumes that you already have created a “.ZLS” file for each ZIP file:
(i.e pkunzip -vn WIN.ZIP > WIN.ZLS).
Then you can generate one file containing a list of all the files within your ZIP files with:
grep -d -a "." *.zls > all_zip.txt

In the following example we will generate a single file with all the batch files on your C: drive
c:
cd \
grep -d -a "." *.bat > all_bat.txt
umore all_bat.txt
 

Might show:
AUTOEXEC.BAT: rem C:\WIN95\net start
AUTOEXEC.BAT: @echo off
AUTOEXEC.BAT: verify on
AUTOEXEC.BAT: break on
AUTOEXEC.BAT: prompt $t $p$g
WIDGETS/samples/xttest/vc20/makeall.bat: call set_ec
WIDGETS/samples/xttest/vc20/makeall.bat: call clean
WIDGETS/samples/xttest/vc20/makeall.bat: cd debug
WIDGETS/samples/xttest/vc20/makeall.bat: call clean
WIDGETS/samples/xttest/vc20/makeall.bat: cd ..
WIDGETS/samples/xttest/vc20/makeall.bat: nmake /nologo DEBUG=1 -f xttest_w.mak
WIDGETS/samples/xttest/vc20/mkd.bat: nmake DEBUG=1 -f xttest_w.mak
WIN95/help/pingname.bat: ping www.microsoft.com
WIN95/help/pingname.bat: ping ftp.microsoft.com
WIN95/help/pingname.bat: @echo off
WIN95/help/pingname.bat: echo ...
WIN95/help/pingname.bat: echo Click the Help window to continue with the Internet troubleshooter.
WIN95/help/pingnum.bat: ping 198.105.232.1
WIN95/help/pingnum.bat: ping 198.105.232.6
WIN95/help/pingnum.bat: @echo off
WIN95/help/pingnum.bat: echo ...
WIN95/help/pingnum.bat: echo Click the Help window to continue with the Internet troubleshooter.
WIN95/save.bat: c:
WIN95/save.bat: cd \win95
WIN95/save.bat: rm -rfl d:\park\win95.zip
WIN95/save.bat: pkzip -pr d:\park\win95
WIN95/save.bat: ls -l d:\park\win*.zip
WINDOWS/d2n.bat: @echo off
WINDOWS/d2n.bat: switch N
WINDOWS/get_osnt.bat: cmd /c ver > c:\ver.tmp
WINDOWS/n2d.bat: @echo off
WINDOWS/n2d.bat: switch D
WINDOWS/oled2n.bat: @echo off
WINDOWS/oled2n.bat: oleswtch N
WINDOWS/olen2d.bat: @echo off
WINDOWS/olen2d.bat: oleswtch D
WINDOWS/oleswtch.bat: @echo off
WINDOWS/tmpdelis.bat: @if exist C:\WINDOWS\tmpcpyis.bat del C:\WINDOWS\tmpcpyis.bat
WINDOWS/tmpdelis.bat: @if exist C:\WINDOWS\winstart.bat C:\WINDOWS\winstart.bat

If the batch files are all in one directory you an also use:
pr -X: -t *.bat > all_bat.txt

16: Return to your home directory from a batch file:

In this example we demonstrate how to save the initial home directory before a batch process starts and
changes directories and the RETURN back to the original directory:

rem **** save initial home directory ****
pwd > %TEMP%/pwd.tmp

rem ****** change to other directories and make a backup ****
cd \src
pkzip -pr \park\src

rem ****** return to the initial home directory ******
ucd @%TEMP%/pwd.tmp

Might show:
C:\SRC\WORK>rem **** save initial home directory ****
C:\SRC\WORK>pwd 1>c:\temp/pwd.tmp
C:\SRC\WORK>rem ****** change to other directories and make a backup ****
C:\SRC\WORK>cd \src
C:\src>rem pkzip -pr \park\src
C:\src>cd \tmp
C:\tmp>rem ****** return to the initial home directory ******
C:\tmp>ucd @c:\temp/pwd.tmp
C:\SRC\WORK>

17: Find the location of a program

Sometimes you might need to know where a specific batch file or program is located.
The PATH environment contains several directories of all your program on your machine.
It would be very tedious to search manually for a program in each of these directories.
UnixDos provides this capability with the WHICH command:

which mybatch

Will search all directories in the PATH environment for any programs with the filename "mybatch".
The extension can be ".bat", ".com" or ".exe".

Might show:
c:/Unixdos/mybatch.bat

To alter the default list of "programs" set your own list of possible file extensions:
set UDPATHEXT=.exe;.com;.bat;.pif;.sh;

Now you can find also PIF files:
which dosprmpt

Might show:
c:/Windows/dosprmpt.pif

18: Break a line with fields into several lines

In some cases you might want to break a line which is separated by a field delimiter into several separate lines.
For example the PATH environment contains a list of all directories with programs and batch files etc.
PATH=F:\MSDEV\BIN;C:\UTIL;C:\WIN95;C:\WIN95\COMMAND

To get a list of directories line by line enter:
sed "s/;/\n/g" ~$PATH

Might show:
F:\MSDEV\BIN
C:\UTIL
C:\WIN95
C:\WIN95\COMMAND

If the "fields.txt" contains:
field1-1,2,a,more text1
field1-2,3,c,more text2
field1-3,6,b,more text3
field1-4,10,d,more text4

To replace the commas with a new line enter:
sed "s:,:\n:g" bed1.txt

The output is:
field1-1
2
a
more text1
field1-2
3
c
more text2
field1-3
6
b
more text3
field1-4
10
d
more text4