ls command refuses to give just folder names per command line switch

Nils Kassube kassube at gmx.net
Sat Nov 28 20:13:54 UTC 2009


Ray Parrish wrote:
> I have been trying to figure out why ls will not return folder names
> only as per the man page's insistence that it will with the -d
>  switch. Here is output from Terminal
> 
> ray at RaysComputer:~/links$ ls --directory
> .
> ray at RaysComputer:~/links$
> 
> No sub folders returned from the ls command.

I think that's OK. What you asked ls to do is list the current directory 
but only the directory, not the contents. And the current folder is ".". 
If you want to list the directories within the current directory you 
could use

ls -d */

instead.

> What I'm trying to get ultimately is a recursive list of all files of
>  a certain type in all sub folders of the current folder, including
>  the current folder. But when I add the --recursive command, and
>  include a *.html on the end, all I get is a list of the .html files
>  in the current folder, and none from any of the sub folders.


Then use the find command. What you want is something like this:

find -type f -name \*.html

> ray at RaysComputer:~/links$ ls -x -1 --recursive *.html

Other than the Windows shell, bash expands this command and replaces the 
"*.html" expression with a list of the .html files in your current 
directory, i.e. something like

ls -x -1 --recursive file1.html file2.html

and those are no directories, so the "--recursive" parameter isn't 
useful here.


Nils




More information about the ubuntu-users mailing list