Suppose you are in a directory that contains many files and many subdirectories.
You want to get a directory listing of all the files beginning with the letter "d". You type
ls d*and what you get back is mostly files in sub-directories (in particular, files in subdirectories that begin with "d").
How do you list only the files and directory names in your current directory?
5 Answers
Ah, I just found it on the 6th reading of the man page. It's the not-so-sensibly named "directory" parameter
ls -d d* 7 I believe another interesting solution to be,
ls | grep ^dOffers the flexibility of regular expressions.
4find . -maxdepth 1 -name d* -type f
Okay, using find here is a tad of overkill. Just a tad.
1ls -ld: It will give the list of directories, without descending into subdirectories.
Example:
ls -ld Cust*
This command will provide a listing of the files and directories which start with Cust.
ls -a | grep "^."
ls -a: it will demonstrate all files and folders (hidden files and unhidden files together)
grep "^.": it will filter the result, and it will choose to show you just the files starts with a point.