All in the <head>

– Ponderings & code by Drew McLellan –

– Live from The Internets since 2003 –

About

Dir vs ls

10 November 2003

If you use linux or Mac OS terminals a lot you’ll be used to typing ls to get a directory listing. For me, it is so deeply seated in physical memory that when my brain thinks “I need a directory listing”, my hands type ls.

On Windows machines, the equivalent command is dir. This is always the second command I type at a Windows command prompt, having failed to beat my hands and intercept the ls that is already trotting from my fingers. Today I got fed up with it. Here’s the solution I devised:

  1. Open a new text file, type: dir
  2. Save as ls.bat in C:\Windows\System32\

Now every time you type ls at a Windows command prompt it will resolve to this batch file. The batch file contains a single command:- dir.

Whilst I’m on the subject of Windows command prompt tips (who’d’ve thought it?!), I also discovered today that (again, like Mac OS and linux) when typing file and folder names you can type the first few letters of the file name and hit tab to autocomplete. You have to type enough letters to make the sequence unique, but that’s not usually very many. For example, from the root of my C drive:

C:\>cd doc[tab][enter]
C:\Documents and Settings>

Isn’t that handy? Don’t say I never give you anything.

- Drew McLellan

Tags

Comments

  1. § Paul: I have a potential solution for you Drew. The one I always use (because I hate DOS/Command prompts but am usually forced to work in it) is to install cygwin (http://www.cygwin.com/) which gives you all your favourite linux command line tools - think grep, awk, sed and you guessed it - ls! I love it.
    Cheers,
    Paul
  2. § vlad: that’s funny, since when i started using linux i had to make an alias ’dir’ for ls ^_^
  3. § george: I have a better process**

    Like all programmers should let’s start at zero.


    0. Open a window(Living room, bedroom, kitchen makes no difference)
    1. Unplug PC (dont want to give it a life line)
    2. Balance PC on ledge.
    3 Shouting out the mantra ”**** Bill Gates” gently push PC outwards

    ** This process only applies to PC’s running Windows

    G
  4. § yafujifide: Just thought I’d point out that for some reason the backslashes in the command prompts you have in this article seem to disappear when I go from the front page to the permanent link. It happens in both Mozilla and IE on Windows XP. I just checked the code and the slashes seem to literally not be there on the permanent link, but on the front page they are there. Odd.

    Otherwise, great suggestion. Using batch files has helped me out many times in the past when I’ve had to use the command prompt in Windows repeatedly. One of my many uses was to create a file that ran the Java compiler. (though I probably could have just copied the compiler to the system folder)
  5. § Eric TF Bat: DOS is good, nowadays. Not a patch on bash/csh/ksh/etc in Unix, but good enough. Things to bear in mind:

    Quoting the DOS help: ”Delayed environment variable expansion is NOT enabled by default.” Type HELP CMD at a command prompt and page down to the section starting with this warning. It will explain how to set things up so it works in Win2000/XP.

    You probably want your LS.BAT batch file to contain the following line:

    @DIR %*

    The ”@” prevents it echoing the command to the output before running. The %* copies over any args you give it. Useful ones:

    /S means search subdirectories, ie recurse—I believe Unix ls doesn’t have this, and you have to use find instead.

    /A means show all hidden files too; the equivalent of ls -a

    /W means go wide
    /B means bare format

    /L means use lowercase format on old DOS 8.3-format filenames

    /P means pause after each screenful, as if you’d typed DIR | MORE

    There’s more; type HELP [command] or [command] /? for the goodies.
  6. § Drew: Thanks, Eric. Good tip.
  7. § David S: If you want to get some of UNIX’s power but keep things simple, there’s always GNU Utils for Windows. I like these because they work great right in my regular cmd window (and it has its own shell too).

    I was never able to get cygwin to function properly and I don’t really need ALL that in Windows. Much better than using the ls.bat (which I used to rely on).
  8. § Baja: Hello! i want information on how to use the Command Prompt and i can’t find from anywhere please give me details on it or anything to know how to master it. Thank u very much. i would be so happy if i receive the answer from you all. i am very interested to know how to use it.
  9. § h0ffa:

    most linux like I could get it was with:

    @dir /w /p %*

  10. § Mike A:

    “… /S means search subdirectories, ie recurse—I believe Unix ls doesn’t have this, and you have to use find instead. …”

    ls -R lists directories recursively

  11. § Ben:

    okay that just made my day. i have the exact same problem, having worked on a lot of unix and linux systems. your batch file idea is what i call “ stickin’ it to the man! “ well done.

Photographs

Work With Me

edgeofmyseat.com logo

At edgeofmyseat.com we build custom content management systems, ecommerce solutions and develop web apps.

Follow me

Recent Links

Affiliation

  • Web Standards Project
  • Britpack
  • 24 ways

I made

Perch - a really little cms

About Drew McLellan

Photo of Drew McLellan

Drew McLellan (@drewm) has been hacking on the web since around 1996 following an unfortunate incident with a margarine tub. Since then he’s spread himself between both front- and back-end development projects, and now is Director and Senior Web Developer at edgeofmyseat.com in Maidenhead, UK (GEO: 51.5217, -0.7177). Prior to this, Drew was a Web Developer for Yahoo!, and before that primarily worked as a technical lead within design and branding agencies for clients such as Nissan, Goodyear Dunlop, Siemens/Bosch, Cadburys, ICI Dulux and Virgin.net. Somewhere along the way, Drew managed to get himself embroiled with Dreamweaver and was made an early Macromedia Evangelist for that product. This lead to book deals, public appearances, fame, glory, and his eventual downfall.

Picking himself up again, Drew is now a strong advocate for best practises, and stood as Group Lead for The Web Standards Project 2006-08. He has had articles published by A List Apart, Adobe, and O’Reilly Media’s XML.com, mostly due to mistaken identity. Drew is a proponent of the lower-case semantic web, and is currently expending energies in the direction of the microformats movement, with particular interests in making parsers an off-the-shelf commodity and developing simple UI conventions. He writes here at all in the head and, with a little help from his friends, at 24 ways.