Results 1 to 10 of 11
Hi all,
Im trying to see a list of the top level items in a directory without getting a list of every single file inside those directories. I want to ...
- 10-21-2011 #1Just Joined!
- Join Date
- Aug 2011
- Posts
- 10
How do I see a list of the directories without a list of every file?
Hi all,
Im trying to see a list of the top level items in a directory without getting a list of every single file inside those directories. I want to use this command:
find /path/to/files -mtime +1 -exec ls {} \;
The directory I want to see has two directories and a .tar file inside it. I just want to have my command find those three items, not list every file inside the two directories as well. How could I modify my command? I tried adding the -d argument to ls, no dice.
Thanks,
Erin
- 10-22-2011 #2
Why can't you just do "ls /path/to/directory"? That should only show you the direct contents of that directory:
Each of {c, perl, ruby} is itself a directory, but they are not expanded.Code:[alex@niamh ~]$ ls ~/test c perl ruby
DISTRO=Arch
Registered Linux User #388732
- 10-22-2011 #3Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
I often like tree, which is fairly flexible, as in this demo:
producing:Code:#!/usr/bin/env bash # @(#) s1 Demonstrate flexible structure listing of "tree". # Section 1, setup, pre-solution, $Revision: 1.23 $". # Infrastructure details, environment, debug commands for forum posts. # Uncomment export command to run script as external user. # export PATH="/usr/local/bin:/usr/bin:/bin" HOME="" set +o nounset pe() { for _i;do printf "%s" "$_i";done; printf "\n"; } pl() { pe;pe "-----" ;pe "$*"; } edges() { _n="$1" _f="$2";head -n $_n $_f; pe " ---";tail -n $_n $_f ; } db() { : ; } db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; } C=$HOME/bin/context && [ -f $C ] && $C tree set -o nounset pe pl " Setup, create structure of directories and files:" db " Section 1: Create directory / file structure." rm -rf d mkdir -p d/d1/d11 d/d2/d21 touch d/f d/d1/f1 d/d1/d11/f11 d/d2/f2 d/d2/d21/f21 tree -a d # Section 2, solution. pl " Results, all directories:" db " Section 2: solution." tree -d d pl " Results, one level:" tree -L 1 -d d pl " Results, one level, full path, no indent:" tree -fi -L 1 -d d pl " Results, one level, no indent, permissions, size :" tree -psh -i -L 1 -d d pl " Results, pretty ascii graphic lines:" LC_ALL="" LANG=en_US.UTF-8 tree -L 1 -d d exit 0
See man tree for details ... cheers, drlCode:% ./s1 Environment: LC_ALL = C, LANG = C (Versions displayed with local utility "version") OS, ker|rel, machine: Linux, 2.6.32-5-686, i686 Distribution : Debian GNU/Linux 6.0 (squeeze) GNU bash 4.1.5 tree v1.5.3 (c) 1996 - 2009 by Steve Baker, Thomas Moore, Francesc Rocher, Kyosuke Tokoro ----- Setup, create structure of directories and files: db, Section 1: Create directory / file structure. d |-- d1 | |-- d11 | | `-- f11 | `-- f1 |-- d2 | |-- d21 | | `-- f21 | `-- f2 `-- f 4 directories, 5 files ----- Results, all directories: db, Section 2: solution. d |-- d1 | `-- d11 `-- d2 `-- d21 4 directories ----- Results, one level: d |-- d1 `-- d2 2 directories ----- Results, one level, full path, no indent: d d/d1 d/d2 2 directories ----- Results, one level, no indent, permissions, size : d [drwxr-x--- 4.0K] d1 [drwxr-x--- 4.0K] d2 2 directories ----- Results, pretty ascii graphic lines: d ├── d1 └── d2 2 directories
PS If you run it and get somewhat different ouput, it may be due to the Google speller, which wants to interpret some sequences as markup, and changed the output somewhat. I think I caught most of the flaws.Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 10-23-2011 #4Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,971
Code:# to just list one directory level, including hidden files that start with a dot. ls -a /path/to/files # to list all the sub-directories ls -aR /path/to/files
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 10-23-2011 #5Just Joined!
- Join Date
- Oct 2011
- Location
- STL, USA
- Posts
- 8
Yes, why does...
ls
...produce a listing while...
ls -d
only gives me "."
???
ls -d * works but ls -d fails...
- 10-23-2011 #6Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
First line in man ls:
So anCode:List information about the FILEs (the current directory by default).
is the same asCode:ls -d
The man pages are your friends. Best wishes ... cheers, drlCode:ls -d .
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 10-23-2011 #7Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,971
From the ls man page:
So, the only directory entry in the current directory is its self-reference, denoted by the dot '.' - so don't use the -d argument. The suggestions I made previously show you what to do.Code:-d, --directory list directory entries instead of contents, and do not dereference symbolic linksSometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 10-23-2011 #8Just Joined!
- Join Date
- Oct 2011
- Location
- STL, USA
- Posts
- 8
- 10-23-2011 #9
Maybe not the best way but
will get you directories only. The others, I'll leave as an exercise for the readerCode:ls -l | grep '^d'
If we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)
My new blog. It's probably not as good as I think it is.
- 10-23-2011 #10Just Joined!
- Join Date
- Oct 2011
- Location
- STL, USA
- Posts
- 8


Reply With Quote
