Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 712
L4reds Avatar asked Aug 06 '13 06:08

L4reds


People also ask

What is the equivalent of ls in Windows Command Prompt?

However, you can use the “ls” command functionality in Windows using the equivalent dir command in Command Prompt. To list files and directories using the Command Prompt in Windows 10 and 11: 1.

What is Unix Command Prompt prompt?

Simply put, a command prompt is an input field in the terminal emulator (CLI) which lets you input/issue commands. The command prompt provides some useful information to the user.

Does Windows have Unix commands?

Windows. Under Windows, one easy way to access a Unix command line shell is to download and install Cygwin. The installer has lots of options, but if you just go through using the defaults, you should end up with an icon on your desktop that will load up a Unix shell.

Why I cant use ls in CMD?

You can't use ls on cmd as it's not shipped with Windows , but you can use it on other terminal programs (such as GitBash). Note, ls might work on some FTP servers if the servers are linux based and the FTP is being used from cmd . dir on Windows is similar to ls .


1 Answers

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.

like image 126
mcalex Avatar answered Nov 15 '22 22:11

mcalex