awk substr

HI I am using awk and substr function to list out the directory names in the present working directory .

I am using below code

ls -l | awk '{ if ((substr($1,1,1)) -eq d) {print $9 }}' 

But the problem is i am getting all the files and directories listed where as the requirement i wrote is for only dircetories.
I even tried below

ls -l | awk '{ if ((substr($1,1,1)) -eq 'd' ) {print $9 }}' 

any help pls?

regards,
p

try this

# awk '{if(substr($1,1,1)=="d")print $9}'
 
ls -l | awk 'substr($1,1,1)=="d"{print $9}'
ls -l | awk '/^d/{print $NF}'

Try like

ls -l|grep ^d

Or:

ls -ld */
1 Like

Oh, yes of course :slight_smile: , so then it becomes

ls -1d */

(only the name should be printed, so 1 instead of l)

try

 du | cut -f2