L4reds
L4reds

Reputation: 412

What is the Windows command prompt equivalent for th unix command 'ls -lah'?

I am beginning to learn node.js. I started by reading the book "The Node Beginner" and the code given there seems to be written for running in unix, and I don't know how to write equivalent code for windows for the part of the code given below.

var exec=require("child_process").exec;

function start(){
console.log("Request handler 'start' was called");

var content="empty";
exec("ls -lah", function(error, stdout, stderr){
    content= stdout;

});

return content;
/*
function sleep(milliSeconds){
    var startTime=new Date().getTime();
    while(new Date().getTime()< startTime+milliSeconds);
}
sleep(10000);
return "Hello Start"; */
}

If you had ever read that book or have any idea about how to make this code work, I'll be very grateful.

Upvotes: 9

Views: 11157

Answers (2)

mcalex
mcalex

Reputation: 6798

The dos/win command dir is the equivalent of *nix's ls

The dir command by default produces a long listing, so you don't need to find an equivalent for the -l parameter.

To produce a listing of all files (ie -a in *nix), you need to indicate that you want readonly, hidden and system files. This is done with /a.

There is no equivalent to *nix's -h parameter which changes the unit of measure for file sizes from bytes to KB, MB or GB with a single letter suffix (e.g., 1K 234M 2G).

So, the nearest equivalent to ls -lah in *nix is:

dir /a

This will produce a long style list (ie will include attributes) of all files which as close as you can get to ls -lah

The /w parameter to dir actually produces the equivalent of the *nix ls command (ie without the long list provided by '-l'), so including this is not technically the correct answer.

Upvotes: 12

L4reds
L4reds

Reputation: 412

Replacing 'ls -lah' with 'dir /w' works just fine.

Upvotes: 0

Related Questions