Cut last blank space

Hello,

I am using this to get only directories :

ls -l | grep '^d'

and here is the result :

drwx------  13 so_nic sonic       13 Nov  4 13:03 GLARY
drwx------   3 so_nic sonic        3 May  6  2010 PSY2R
drwx------  15 so_nic sonic       15 Oct 14 08:47 PSYR1

But I only need to keep this :

GLARY
PSY2R
PSYR1

Thanks

ls -l | grep '^d' | tr -s " " | cut -d" " -f9
1 Like
for x in *; do
    [ -d "$x" ] && echo "$x"
done

Regards,
Alister

1 Like

If "/" at the end are allowed,

ls -1F | grep '/$'

or even,

printf "%s\n" */

Of-course they can be stripped off if not needed.

O/P:

GLARY/
PSY2R/
PSYR1/
1 Like

Thanks all works great.

Thanks

for d in */; do
  echo "${d%/}"
done
1 Like

Caveat: Without a check, that could print "*/" when there's no directory.

ls -l |awk '/^d/ {print $NF}' 
1 Like