Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

On my user folder, I have folders like D ropbox, D ocuments, D ownloads & d ump.

ls a* should list all the files whose name starts with a. Right? But when I gives the command ls d*, instead of just displaying dump it shows me the ls of dump directory. And When I gives the command as ls D*, then it displays ls of all foldes starting with D

So what part did I miss in understand it?

Edit: Attaching a screenshot

share|improve this question

2 Answers 2

up vote 10 down vote accepted

According to bash man page:

bash scans each word for the characters *, ?, and [. If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of file names matching the pattern

and from info node for ls

The `ls' program lists information about files (of any type, including directories). Options and file arguments can be intermixed arbitrarily, as usual.

For non-option command-line arguments that are directories, by default 'ls' lists the contents of directories, not recursively, and omitting files with names beginning with '.'. For other non-option arguments, by default `ls' lists just the file name. If no non-option arguments are specified, 'ls' lists the contents of the current directory.

so when yo give ls d*, d* is expanded to sorted list of all file/directory names starting with d. So you command becomes

ls dump

and as dump is a directory name so you get the listing of all files in the directory "dump' but when you give ls D*, D* is expanded to "Desktop Documents Downloads Dropbox", so the command becomes

ls Desktop Documents Downloads Dropbox

and as all of these are directories, you get the listing of files in individual directory. If there was a file starting with D in current directory it would have been listed seperately.

share|improve this answer

ls d* and D* both list files and folders matching d* and D* respectively, the behaviour is the same, there must have been a mistake on your test.

If you want to list only the folder names and not the folder contents you need to use "-d":

ls -d D*
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["                  <li><a href=\"//area51.stackexchange.com\" title=\"proposing new sites in the Stack Exchange network\">Area 51</a></li>\r\n                        <li><a href=\"//careers.stackoverflow.com\">Stack Overflow Careers</a></li>\r\n                    \r\n                </ol>\r\n            </td>\r\n    </tr>\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &#169; 2015 stack exchange inc; user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc by-sa 3.0</a> \r\n                with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2015.5.22.2603\r\n            </div>\r\n                <div id=\"additional-notices\">\r\n                    Ubuntu and Canonical are registered trademarks of Canonical Ltd.\r\n                </div>\r\n            \r\n        </div>\r\n    </div>\r\n    <noscript>\r\n        <div id=\"noscript-wa"], "copyright__copyright__copyright": ["y.\n\nshare|improve this answer\n\nls d* and D* both list files and folders matching d* and D* respectively, the behaviour is the same, there must have been a mistake on your test.\n\nIf you want to list only the folder names and not the folder contents you need to use \"-d\":\n\nls -d D*\nshare|improve this answer\n\nYour Answer\n\n\u00a0\ndiscard\n\nBy posting your answer, you agree to the privacy policy and terms of service.\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}