Prev: commenting all lines with a particular substring
Next: [announcement] runawk-0.21.0 -- yet another power tool to program in shell
From: aioe on 1 Apr 2010 01:46 On 3/31/2010 12:43 PM, Janis Papanagnou wrote: > If it's only typing convenience for a specific job you often do, then > use an alias or a function definition for that command in your profile. I've been using a script, but your ways have the advantage of avoiding unnecessary file proliferation. The original question was prompted by the suspicion that I was overlooking some tricky way to invoke ls.
From: Thomas 'PointedEars' Lahn on 1 Apr 2010 08:44 Barry Margolin wrote: > aioe wrote: >> pk wrote: >> > So, "ls -l directory" shows the files in the directory; "ls -ld >> > directory" shows the properties of the directory itself. >> For that, I just invoke ls -l from one level higher in the directory >> tree, but I suppose -d might be useful in scripts. > > If you do that, Do what? > it shows all the other files and directories in the parent directory. ls -d $FOO shows all non-hidden files matching the value of `$FOO' starting from the current directory, without descending if `$FOO' matches a subdirectory. > How do you do it if you just want to list the > properties of that one directory? "ls -l | grep foo"? "Properties"? But I think I have answered that question already: ls -d * PointedEars
From: pk on 1 Apr 2010 09:14 Thomas 'PointedEars' Lahn wrote: > Barry Margolin wrote: > >> aioe wrote: >>> pk wrote: >>> > So, "ls -l directory" shows the files in the directory; "ls -ld >>> > directory" shows the properties of the directory itself. >>> For that, I just invoke ls -l from one level higher in the directory >>> tree, but I suppose -d might be useful in scripts. >> >> If you do that, > > Do what? > >> it shows all the other files and directories in the parent directory. > > ls -d $FOO > > shows all non-hidden files matching the value of `$FOO' starting from the > current directory, without descending if `$FOO' matches a subdirectory. > >> How do you do it if you just want to list the >> properties of that one directory? "ls -l | grep foo"? > > "Properties"? But I think I have answered that question already: You have *completely* failed to understand what Barry meant (or at least, that's what I hope).
From: Barry Margolin on 1 Apr 2010 21:29 In article <1715801.PVSPYKUYFu(a)PointedEars.de>, Thomas 'PointedEars' Lahn <PointedEars(a)web.de> wrote: > Barry Margolin wrote: > > > aioe wrote: > >> pk wrote: > >> > So, "ls -l directory" shows the files in the directory; "ls -ld > >> > directory" shows the properties of the directory itself. > >> For that, I just invoke ls -l from one level higher in the directory > >> tree, but I suppose -d might be useful in scripts. > > > > If you do that, > > Do what? Use "ls -l <parent>" instead of "ls -ld <directory>". > > > it shows all the other files and directories in the parent directory. > > ls -d $FOO > > shows all non-hidden files matching the value of `$FOO' starting from the > current directory, without descending if `$FOO' matches a subdirectory. But I was responding to a post that said how he gets the attributes of a directory without using the -d option. You're using the -d option, so what does that have to do with it? > > > How do you do it if you just want to list the > > properties of that one directory? "ls -l | grep foo"? > > "Properties"? But I think I have answered that question already: > > ls -d * That shows the properties of lots of files, directories, symlinks, etc., not just "that one directory". And you're using the -d option, which he was saying he doesn't use. -- Barry Margolin, barmar(a)alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** *** PLEASE don't copy me on replies, I'll read them in the group ***
From: Eric on 2 Apr 2010 08:18
On 2010-03-31, aioe <worKEEPSPAMOUTwor(a)bellsouth.net> wrote: > Is there some way to use the ls command that is equivalent to > "find . -type d" ? No. That find command means "Show me the names of all the directories from here on down." It does not show the files in those directories. > If not, what is the -d option good for? ls shows the names (and properties with -l) of every name given to it as an argument. If there is no argument, it behaves as if . was specified. For each of the arguments that is a directory, it shows the contents of that directory, but not recursively. The -R option makes it recursive, so that for every directory that is listed, the contents are also listed as if the directory had been an argument. The -d option means "If an argument is a directory, just list it (and properties if requested), _not_ its contents". I find I have two uses for the -d option: ls -ld to check on the ownership and permissions of the current directory (this is the same as ls -ld . ) ls -ld foo* to see which foo archives and directories I have, e.g. drwxr-xr-x 2 eric realusers 4096 2010-04-02 12:57 foo21 -rw-r--r-- 1 eric realusers 0 2010-04-02 12:57 foo21.tar.gz -rw-r--r-- 1 eric realusers 0 2010-04-02 12:57 foo22.tar.gz There is no simple equivalent to either of these without using the -d option. As an aside, some people seem to not realise that it is the shell that expands foo*, ls thinks it was called with ls -ld foo21 foo21.tar.gz foo22.tar.gz This is the reason why ls and ls * are not the same thing. As another aside, ls -Rd just lists . because -d prevents any action on a directory other than just listing it. Eric |