


       UNIX on DOS Toolkiit (UNXIDOS)                                  Tips
                               Version 3.0


                             UNIX  Power  Tools for  DOS

                                     (UNIXDOS)O


                                        TIPS
















































       OB. Eichberger, Professional Software Solutions
                                  Page 1



       UNIX on DOS Toolkiit (UNXIDOS)                                  Tips
                               Version 3.0



       Cleanup temporary files_______________________________________________3

       Find space hoogs______________________________________________________3

       Find documents via a search string____________________________________3

       Get Disk Space and Directory Overview_________________________________4

       Find all files you worked on today____________________________________5

       Alphabetical list of all files on your machine________________________5

       Measure elapsed Time for (batch) process______________________________5

       Find directories in the root directory________________________________5

       String numbers on one single line_____________________________________7

       User Prompt Example___________________________________________________9

       Loop Example_________________________________________________________11

       Process each line in a file__________________________________________12

       View many small files together_______________________________________13

       Return to your home directory in a batch file:_______________________14

       Find the location of a program_______________________________________15

       Break a line into several lines______________________________________15






















       OB. Eichberger, Professional Software Solutions
                                  Page 2



       UNIX on DOS Toolkiit (UNXIDOS)                                  Tips
                               Version 3.0

       In this section I will present several practical and usefull examples
       how to apply the powerful UNIXDOS utilities.


       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.
       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 `
                                                     `/temp'
                                                            ' directory:
       @echo off
       echo /tmp ...
       cd \tmp
       rm -lf *
       echo /temp ...
       cd \temp
       rm -lf *
       echo *.tmp ...
       cd \
       ufind / -name '*.tmp' -exec rm -lf {} ;
       ufind / -name '*/xx*' -exec rm -lf {} ;


       Find space hoogs

       Many times you might get tight on disk space and want to know where all
       the space goes.
       The following command will search the entire current hard disk and show
       you very quickly all the files which are larger than one megabyte
       (1,000,000 bytes):
       ufind / -size +1m -ls    or
       ufind / -size +1000000c -ls

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


       Find documents via a search string

       In some cases when you have many documents(*.doc, *.txt) across many
       different directories you might forget where a particular document
       resides. With the following command you can easliy find the document if
       you remember at least one failry unique text string in that document:
       grep -d -i string *.doc *.txt




       OB. Eichberger, Professional Software Solutions
                                  Page 3



       UNIX on DOS Toolkiit (UNXIDOS)                                  Tips
                               Version 3.0


       Get 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:
       cd /
       du > all.du

       The output might look like:
          Megabytes
                ---   ./ctree
             4.4892   ./cvision
                ---   ./e100b
             2.7525   ./msoffice/access/sampapps
            16.4495   ./msoffice/access
            13.9919   ./msoffice/clipart/pcsfiles
            16.9738   ./msoffice/clipart
       ...
            85.1968   ./msoffice
             0.2294   ./msvc/bin/video
            19.2020   ./msvc/bin
             5.7999   ./msvc/debug
            70.9100   ./msvc/help
       ...
           230.0969   ./msvc
       ...
             0.2949   ./windows/msapps/artgalry
             0.6554   ./windows/msapps/equation
             2.4248   ./windows/msapps/grphflt
             0.5898   ./windows/msapps/msgraph
             2.2610   ./windows/msapps/msgraph5
             1.7695   ./windows/msapps/msimager
             0.7209   ./windows/msapps/msinfo
             1.8678   ./windows/msapps/msquery
             1.1796   ./windows/msapps/orgchart
             1.7039   ./windows/msapps/proof
             0.0655   ./windows/msapps/sheetcnv
             1.9988   ./windows/msapps/textconv
             0.3932   ./windows/msapps/wordart
            15.9252   ./windows/msapps
            69.3699   ./windows/system
             0.2621   ./windows/temp
           243.7284   ./windows
                ---   ./winproj
          1903.6570   .

       Showing you empty directories you could remove and the space used for
       each branch.





       OB. Eichberger, Professional Software Solutions
                                  Page 4



       UNIX on DOS Toolkiit (UNXIDOS)                                  Tips
                               Version 3.0


       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 (example Oct 17, 8:10 am):
       touch 10170810 /today.ref

       We confirm that the new file has the correct file details:
       ls -l /today.ref
       -rw-rw-rw-      0 Oct 17  1996 /today.ref

       Now we can enter the UFIND command:
       ufind / -newer /today.ref -ls



       Alphabetical list of all files on your machine

       Get file list with full path name:
       cd /
       ufind / -print > all.lst
       basename < all.lst > all_b.lst


       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 initialize the timing sequence:
       uptime -i

       Then you can do your processing.
       To get the elapsed time enter:
       uptime
       And it will display something like (which means 20 seconds since the
       `
       `uptime -i'
                  ':
       00:00:20 elapsed since reboot at:

           Fri Oct 25 11:02:56 1996


       Find directories in the root directory

       To find all the main directories in your root directory enter:
       ufind / -type d -level 1 -print

       Might display:
       /dos
       /msoffice
       /msvc
       /windows




       OB. Eichberger, Professional Software Solutions
                                  Page 5



       UNIX on DOS Toolkiit (UNXIDOS)                                  Tips
                               Version 3.0
























































       OB. Eichberger, Professional Software Solutions
                                  Page 6



       UNIX on DOS Toolkiit (UNXIDOS)                                  Tips
                               Version 3.0


       String numbers on one single line

       In some cases you might have a text file containing a number of 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 command will string five items per line:
       paste - - - - - < list.txt
       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
       The result would be:
       181     300     97      2142    221
       267     234     288     190     117
       33      195     263     295     1617
       1547    627     284     605     426

       OB. Eichberger, Professional Software Solutions
                                  Page 7



       UNIX on DOS Toolkiit (UNXIDOS)                                  Tips
                               Version 3.0

       1013    94      74      273     569
       129     610     569     783     1
       918     832     454     811     130
       210     145     86      1194



















































       OB. Eichberger, Professional Software Solutions
                                  Page 8



       UNIX on DOS Toolkiit (UNXIDOS)                                  Tips
                               Version 3.0


       User Prompt Example

       The following batch file shows several examples how to prompt the user
       for input:
       . USRCHAR get a single character without return
       . USRPRMPT     get a text from the user and write to `usrprmpt.tmp'
         (i.e. filename)
       . LINE         read one line and send it to standard output

       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

       OB. Eichberger, Professional Software Solutions
                                  Page 9



       UNIX on DOS Toolkiit (UNXIDOS)                                  Tips
                               Version 3.0

       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 succesfully










































       OB. Eichberger, Professional Software Solutions
                                 Page 10



       UNIX on DOS Toolkiit (UNXIDOS)                                  Tips
                               Version 3.0


       Loop Example

       In this example I 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





















       OB. Eichberger, Professional Software Solutions
                                 Page 11



       UNIX on DOS Toolkiit (UNXIDOS)                                  Tips
                               Version 3.0


       Process each line in a file

       In this example I demonstrate how to process each line in a file list.

       The following script will create a list of all batch files and process
       one file at a time until the file is exhausted (see test_lst.bat):

       @echo off
       rem *** DEFINE WORKFILE AND LINE NUMBER ***
       set LINE=1
       set LST=test_lst.txt

       rem *** FILL FILE LIST ***
       ls *.bat > test_lst.txt
       :LOOP
           rem *** GET NEXT LINE ****
           getlines %LINE% %LINE% %LST% > name.tmp
           if errorlevel 1 goto END

           rem *** THIS IS JUST  AS INFORMATION AND CAN BE REMOVED ***
           echo %LST% LINE %LINE% = %NAME%

           rem ****** YOUR PROGRAM HERE *******************
           rem env your-prog @name.tmp
           env uecho @name.tmp

           rem ****** COMPUTE NEXT LINE ***
           call setenv "LINE=`expr $LINE + 1`"
           goto LOOP

       :END
       del name.tmp


       Will print:
       test_lst.txt LINE 1 = x1.bat
       test_lst.txt LINE 2 = x2.bat
       test_lst.txt LINE 3 = x3.bat
       test_lst.txt LINE 4 = x4.bat
       test_lst.txt LINE 5 = cc.bat
       test_lst.txt LINE 6 = go.bat













       OB. Eichberger, Professional Software Solutions
                                 Page 12



       UNIX on DOS Toolkiit (UNXIDOS)                                  Tips
                               Version 3.0


       View many small files together

       If you have many small files and want to print them you can either
       print one page per file or contatinate all files into one file, but
       loose the filename.
       The following command allows you to create a concatinated output WITH
       the leading filename:
       grep -a `
               `.'
                  ' *.txt

       Might show:
       comm1.txt: 1
       comm1.txt: 2
       comm1.txt: 3
       comm1.txt: 4
       comm1.txt: 5
       comm1.txt: 6
       comm2.txt: 1
       comm2.txt: 3
       comm2.txt: 5
       comm2.txt: 7
       comm2.txt: 9
       cut.txt: 1|2|3|4|5|6
       cut.txt: from|to|min|max
       cut.txt: A|B|CCC|D|E|F
       cut.txt: no delimiter
       cut.txt: |two|three|four|five
       diff1a.txt: A
       diff1a.txt: NEW1-1
       diff1a.txt: B
       diff1a.txt: NEW1-2
       diff1a.txt: C
       diff1b.txt: A
       diff1b.txt: B
       diff1b.txt: NEW2-1
       diff1b.txt: NEW2-2
       diff1b.txt: C
       grep1.txt: just text
       grep1.txt: text with number 18
       grep1.txt: 18
       grep1.txt: before 18 after
       grep1.txt: 1818













       OB. Eichberger, Professional Software Solutions
                                 Page 13



       UNIX on DOS Toolkiit (UNXIDOS)                                  Tips
                               Version 3.0


       Return to your home directory in a batch file:

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

       rem **** save initial home directory ****
       pwd > %TMP%/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 @%TMP%/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>



























       OB. Eichberger, Professional Software Solutions
                                 Page 14



       UNIX on DOS Toolkiit (UNXIDOS)                                  Tips
                               Version 3.0


       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'
                '.


       Break a line into several lines

       In some cases you might want to break a line which is separated by a
       field demlimiter into several separate lines.
       The file `
                `bed1.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









       OB. Eichberger, Professional Software Solutions
                                 Page 15
