Now, ya see, on Linux, if you just wanna look at them folders—directories, they call ’em—well, it’s not all that hard. There’s plenty ways to do it. Now, I’ll be tellin’ ya step-by-step here, nice and easy, so you can get just them directories poppin’ up on that screen of yours.
1. Startin’ with ls
Command
First off, most folks use ls
command. Simple as pie, right? You just type ls
, and poof, there’s all the stuff in your directory. But, see, if you only want them directories showin’ up—none of them pesky files clutterin’ your screen—then you gotta add a little extra to that command.
ls -d /
: This one here, you type it in just like that,ls -d /
, and only them directories pop up. None of the other files. It’s just gonna show ya the directories in the current folder.ls -l | grep ^d
: Now if you want it to look all fancy-like with more details, tryls -l | grep ^d
. That’s gonna list out only directories, but in a long format, tellin’ ya things like permissions, owners, all that jazz.
2. Usin’ find
Command
Next, if you really wanna get all directories, even the ones sittin’ inside other directories, find
command’s your friend. It’s a bit more powerful, ya see.
find . -type d
: This one will search through the whole directory you’re in right now, findin’ every single folder. You just typefind . -type d
, and there they are. Simple as that.find /path/to/folder -type d
: Now, if you got a specific folder in mind, just change that/path/to/folder
to wherever you wanna look. Maybe you wanna look in/home
or/var
—you name it.
3. Another Way with tree
Command
If you got tree
installed, well, that’s another handy tool. You just type tree -d
, and it’ll give ya a nice tree-like view of all them directories. Just directories, mind ya, none of them files messin’ up your list.
tree -d
: Shows ya only directories in a tree structure. Helps ya see where each directory sits, nice and clear-like.
4. Tryin’ dir
Command
Another little trick is to use dir
. Now, most folks stick to ls
, but dir
is real similar. You type dir
followed by some options, and it’ll also list directories.
dir -d /
: This is just like thels -d /
trick. Same outcome, so it’s up to ya if you preferdir
overls
.
5. Little Bonus with echo
and grep
Alright, here’s a little hack for ya. If you wanna get all directories and know their names without much fuss, you can use echo
and grep
together.
echo /
: Now, this one’s easy. You just typeecho /
, and it’ll print out the names of directories in the current folder. It’s real quick, if ya just need the names.
Now, that’s about all ya need to get them directories listed out. Pick whichever method suits ya, and you’ll have all your folders poppin’ up on screen in no time!
Tags:[linux, list directories, ls command, find command, tree command]