Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×
User Journal

Journal the_mad_poster's Journal: A Few Unix Tools On Windows... Written In Perl 12

Update: Heh.

Because I am, again, banned from posting at this IP (even though I haven't posted here in over 4 days, and only got one downmod on this IP address in about a week), I am now deluging you with JEs.

This is probably useless to most people thanks to the cygwin environment and actual ports of the GNU utilities, but let me explain...

At work, I am not allowed to download and install applications. I frequently found myself pining for grep, but didn't want to waste my time trying to get somebody to install it for me. So, since I have perl on my system, I built my own customized version. From there, I thought "man, it would be nice if I could run this from anywhere with just 'grep'", so I made "alias". Well, after awhile, I collected the few tools I thought I needed, and now I'm putting them out for anyone who might want their own copy of the set. The tools don't necessarily (actually, they don't USUALLY) function just like the UNIX equivalents because I customized them to my needs and left a lot of stuff I didn't need out, but hey, they're good for study if nothing else.

Note that you will need Perl installed to run these. You can get a Windows Perl installer from http://www.activestate.com/.

Here are the tools in the system:

grep
search for files (sort of like UNIX's find command) or search text for strings matching a pattern.
 
alias
map a new command name to an existing command. For example, 'alias "dir /p /AD" dp' will give you a command named 'dp' that displays only directories and pauses with each screenful of results. Note that you have to surround arguments with spaces with "..".
 
clear
Runs 'cls'
 
rm
Runs 'del'
 
count
Display a line, character, and characters/line count of a file.
 
touch
Create an empty file.
 
ifconfig
Runs 'ipconfig'
 
ls
Runs 'dir'
 
man
Runs 'help'
 
uname
Runs 'ver'
 
yes
Runs ';'. Guaranteed to always return a successful exit status.
 
dump
Outputs a *.bat listing of windows/system32 (unless you have your own .bat files in there, it just tells you what unix-like commands you have on the system).

With the exception of touch, grep, alias, and count, most of this is just a bunch of .bat files that were created with alias (all 'alias' does here is create a .bat file that executes the "real" command, passing along any arguments you supply).

Important Usage Notes


  •  
  • When providing a directory to grep, count, touch or alias, you're expected to use the / separator. You'll have to surround the pathname with double quotes ("..") because / in Windows terms is the character that signifies the start of a command argument. If this bothers you, you can usually use \ instead, but some output may look funny.
  •  

  • Remember, any single argument that has spaces in it - and this is especially common when using alias - must be surrounded by double quotes. This is not strange, you have to do the same thing in UNIX-y systems, you just use single quotes instead.
  •  

  • Whenever something wants a "pattern" as an argument - grep, for example - it expects the pattern to be interpretable by Perl. If you want to force literal interpretation, use '^your_string_here$'. Particularly useful for finding files with grep.
  •  

  • Do not alias alias to alias! Seriously. Go for it. I dare you to try it. Chicken. Braaaak-brak-brak-brak.

Download here and simply unzip the contents into your windows/system32 directory. The system assumes you installed perl at "c:/perl/bin/perl", so, if you didn't, you'll have to go through each file (.bat and .pl) and change the paths to point to the right place or none of it will work right.

Update: I don't know why this keeps defaulting to "Comments Disabled"....

This discussion was created by the_mad_poster (640772) for no Foes, but now has been archived. No new comments can be posted.

A Few Unix Tools On Windows... Written In Perl

Comments Filter:
  • Wish I saw em last week - I just reformatted back to Linux again instead.
  • Say perhaps knoppix? :-) Though you might get your ass handed to you if someone noticed you booted into linux, I dunno.
  • This is perfect! I'm working at an AD site right now over a Citrix connection, and I'm already miserable without my MKS-ified dos windows... this I can copy in without the admins feeling like I've contaminated their Win03 servers.

    Thanks tons...

    Pixie
    • Except that perl isn't installed. Somehow I briefly forgot that critical part of your JE...

      Sigh. Thanks anyways, TMP!

      Pix
      • I'll try and make you a self-contained diskette-sized distro. It can be done, it just takes a little finageling.

        No promises though, Ms. Pixie.
        • Awww, you are so nice to me! If it works out, that would be lovely! But if not, I still really appreciate you looking into it...

          You cheered me up after a dreadful night of desperate shopping, thank you!

          Pixie
      • Except that perl isn't installed. Somehow I briefly forgot that critical part of your JE...

        Hey, has anyone played with ActiveState's ability to compile Perl for Win32? I think it requires the purchase of their IDE, is it actually worth it?

        Cheers,
        =Blue(23)
  • ppt.perl.org - Perl Power Tools. Unix tools written in Perl, and fairly complete.

    Seriously guys, google around a bit before reinventing the wheel.

  • Changing some of your environment variables will give you a more customized behaviour.

    http://www.ka.net/jmenees/Dos/Set.htm [ka.net]

    For example, if you want to list your directories differently, use SET DIRCMD=.

    You can put this in a batch file that sets the appropriate variable, runs the command using the rest of the parameters (%2 %3 %4 .. %9), then UNSET DIRCMD. This way, you can have different batch files that do different things with the same command.

    Also, you might not be allowed to install software, but y

Computers are useless. They can only give you answers. -- Pablo Picasso

Working...