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:
- Open a new text file, type:
dir - Save as
ls.batinC:\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.




Comments
Cheers,
Paul
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
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)
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.
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).most linux like I could get it was with:
@dir /w /p %*
“… /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
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.