command to list directories only
i'm sure this has ben asked before, but in MSDOS there was a command that listed (for the most part) only the directories (dir *, as most nondirectory files had 3 letter extentions and just * displayed files without extentsions) is there any way to do this in linux, display just directories that is?
|
Since Linux considers extensions as part of the file name, I doubt if this can be accomplished. So anything you do will result in listing all the files, and not just the directories.
|
Maybe not exactly what you're looking for, but try "ls -l |grep ^d"
Or "ls -F |grep \/$" |
haha, this looks a lot like the old DOS thing:
ls -xd `ls -F |grep \/$` |
Try the find command instead of ls. The following will list only subdirectories of the PWD:
find ./ -type d This will list *ALL* subdirectories (and their subdirectories), so you may want to limit it with the following: find ./ -type d -maxdepth 1 Take a look at the man page for find for more info. Enjoy! --- Cerbere |
A little AWK goes a long way
Code:
ls -l | grep ^d | awk '{print $9}' Then using awk to print only the 9th column of data... Results: Only the directories are listed. If you want all the info too... remove the AWK pipe |
doesn't work for spaces
the last suggestion:
Quote:
Code:
ls -l | grep ^d | awk '{for (i = 9; i <= NF; i++) printf("%s ",$i);printf("\n")}' (I prefer the find version myself :) ) |
Old thread!
Haha, this thread is so olden! Found this while crawling on google and decided to contribute.
You may use the following to list all dirs in the current dir (not recursive). It also outputs dir permissions so might be useful when permissions are relevant. Code:
ls -lad */ |
Hi,
lets have directory structure: Code:
$ ls -a Code:
$ ls -lad */ |grep test Code:
$ ls -ld */ |grep test Code:
$ uname -a jG |
'.test' is not a directory ?
// never mind Yes it's normal The reasoning is probably the following (not 100% sure): The wildcard is substituted by bash. And bash does not include the the hidden files in the expansion (substitution). |
Well this is an old thread.
To expand on the previous post, yes, the dotfiles aren't being shown since it's the shell doing the expanding, and shell globbing ignores hidden files by default. In fact because the shell is the program doing all the work, it's not even necessary to use ls at all (unless you want long-form information). A simple echo will do just as well. As shown before, the way to glob-match directories is to add a slash after the glob pattern. Code:
echo */ Bash from version 4 also has a recursive globbing pattern. Code:
printf '%s\n' **/ You can also recursively glob for files by adding additional globbing patterns after it. Code:
printf '%s\n' **/*.txt #lists all text files in the current directory and below To print hidden files, simply enable the dotglob option first. To exclude certain entries from the list, you can add patterns that match them to the GLOBIGNORE shell variable (colon-separated), or with extended globbing patterns. Code:
shopt -s dotglob globbing extended globbing In any case, for more complex matching, find is definitely the tool of choice. Be sure to use the -print0 null-terminator option if you need the list to be read by other commands. http://mywiki.wooledge.org/UsingFind http://www.grymoire.com/Unix/Find.html |
I use this script quite often:
Code:
#!/usr/bin/perl Code:
chmod +x lsdir.pl |
This worked for me
for f in `ls -R * | grep ":$" | tr ":" " "` do #do whatever with $f here, including .. if [ -d $f ] then chmod +x $f fi done |
DOS =
Code:
/dir /ad /b Code:
\ls -1d ~/* Edit: That looks funny here, but it is a -"OneD" |
rrow this thread is a question i posted eight years ago, thanks for the info but I'm gonna mark it as 'solved' so it gets a proper burial
|
All times are GMT -5. The time now is 07:54 PM. |