piping ls -l to grep to return directies - TechRepublic
General discussion
April 18, 2001 at 06:35 PM
carol

piping ls -l to grep to return directies

by carol . Updated 25 years, 1 month ago

Hi,
I am not a seasoned Unix user, and here is the task at hand that I’ve been working on. This is an instuction I’ve been asked to perform (Question posed by instructor):
To obtain a long directory listing of current directy and pipe to grep, and ONLY return directory listings.

..Here’s what I’ve come up with… and I’m wondering if I’m way out there in left field>
ls -l |grep -v [-][r-][w-][e-][r-][w-][e-][r-][w-][e-]

The reason I selected to filter for any rows beginning with the -, is I tested to see if I could create a file name starting with – and I couldn’t *but* I could create files named drwxrwxrwx and d-wx-wxr-x etc etc… but I do get an additional line telling me how many entries were in the directory listing. Naturally I could pipe to another filter…*but* I’m rather expecting that, that was not in the instructor’s scheme of things ;-)…

Is there syntax I can use with grep to specify that the d is the first and only character in a line? I have read that UNIX doesn’t look at ‘s or .. so..? 🙂

Thanks any help is appreciated!

This discussion is locked

All Comments