?

Log in

No account? Create an account

linux 'ls' question

« previous entry | next entry »
Apr. 1st, 2007 | 09:32 am
mood: busybusy

so, let's say I want to see only the directories, not files, in the current directory. only the names, not their contents.

is there an option to 'ls' for that? I can't seem to come up with one.

Bonus: Also, don't show me any of the hidden (beginning with a dot) folders.

This would work, except that I want the output in the normal-looking ls - C style columns:
ls -F | grep /

This is what I came up with (in bash), but there must be a better way:
find -maxdepth 1 -type d -name '[!.]*' -printf '%f ' | xargs ls -d 2>/dev/null

Link | Leave a comment | Share

Comments {14}

Chef Monkey

(no subject)

from: chefmonkey
date: Apr. 1st, 2007 10:17 pm (UTC)
Link

ls -d */

Reply | Thread

Triple Entendre

ah!

from: triple_entendre
date: Apr. 2nd, 2007 08:51 am (UTC)
Link

that's better, but not perfect. this solution adds a '/' to the end of each directory name whether I wanted one or not (sometimes I just use color to distinguish them). If I use the -F option with this, I get *two* '/''s at the end of each directory name.

you get an A-.

;-)

Reply | Parent | Thread

Triple Entendre

and one might think

from: triple_entendre
date: Apr. 2nd, 2007 09:00 am (UTC)
Link

and one might think that the GNUism
--indicator-style=none
would help... but no! by putting the trailing slash in the request, it is considered part of the filename. again,
--indicator-style=slash
gives us *two* slashes here.

Reply | Parent | Thread

Re: and one might think

from: anonymous
date: Apr. 2nd, 2007 03:32 pm (UTC)
Link

Well, you seem to be willing to jump through hoops to maximize specific aesthetic properties, so:

ls -d */ | sed s,/,, | xargs ls -d

(It's arguably less convoluted than your previous "perfect" solution)

Alternately:

ls -Cd */ | sed s,/,\ ,g

(Similar, but makes slightly less efficient use of number of available columns -- and has bad interactions with flags like -p)

Reply | Parent | Thread

Chef Monkey

Re: and one might think

from: chefmonkey
date: Apr. 2nd, 2007 03:35 pm (UTC)
Link

Of course, that was me. If you reply, reply to this -- otherwise I'll likely not see the reply.

Reply | Parent | Thread

JP Sugarbroad

Re: and one might think

from: taral
date: Apr. 3rd, 2007 02:00 am (UTC)
Link

I'd do this:

echo */ | sed -e 's,/,,g' | xargs ls -d

Reply | Parent | Thread

Chef Monkey

Re: and one might think

from: chefmonkey
date: Apr. 3rd, 2007 02:09 am (UTC)
Link

Ah, yes! Much lighter weight. One built-in and three externals instead of four externals. Bravo.

Reply | Parent | Thread

Triple Entendre

Re: and one might think

from: triple_entendre
date: Apr. 3rd, 2007 02:21 am (UTC)
Link

I like it, but for some reason echo */ doesn't work in my bash shell, nor with /bin/echo.

echo *, on the other hand, behaves like one would expect. But this doesn't help us here. Hmmm....

Reply | Parent | Thread

Triple Entendre

Re: and one might think

from: triple_entendre
date: Apr. 3rd, 2007 02:23 am (UTC)
Link

because, duh, I was running it in a directory which contained only files.

Reply | Parent | Thread

JP Sugarbroad

Re: and one might think

from: taral
date: Apr. 3rd, 2007 04:50 am (UTC)
Link

Ahahahaha.

Reply | Parent | Thread

JP Sugarbroad

Re: and one might think

from: taral
date: Apr. 3rd, 2007 04:50 am (UTC)
Link

If echo */ doesn't work, how come ls */ does?

Reply | Parent | Thread

Triple Entendre

Re: ah!

from: triple_entendre
date: Apr. 2nd, 2007 09:07 am (UTC)
Link

which isn't entirely fair, since I didn't make it clear that this was a disqualifier in my negative (first) example.

Reply | Parent | Thread

Nathaniel Eliot

(no subject)

from: temujin9
date: Apr. 2nd, 2007 03:07 am (UTC)
Link

ls -ald * | grep ^d

Reply | Thread

Nathaniel Eliot

(no subject)

from: temujin9
date: Apr. 2nd, 2007 03:09 am (UTC)
Link

Ooop, missed the 'C-style' requirement. chefmonkey got it right.

Reply | Parent | Thread