I was writing a quick little script today... well, at least it started out as a quick little script, but it needed to be able to read the directory names from an arbitrary place in my file structure. I thought, sure, the
After spending too long experimenting with various things I checked the net to see if anybody else knew the answer to what I was starting to think I was too stupid to see. It seems many other people have come up against this deficiency in the
but that has three failings. It prints the entire path, lists the directories with a trailing slash (the -d option), and doesn't see hidden dirs (those that begin with a dot). It is easy to use
and a little more fussing with
Another common solution is to use the
This works but puts all the output on one line, precedes each file with its path, the first line is always the name of the directory being listed, and the file list is all jumbled up. I can use the -printf option of file to fix the path problem and to put each name on its own line, getting rid of the first line is just a matter of piping through the tail command, and pipe through the sort command to organise the result.
That took a lot more hassling than I expected. Weird. You'd think that the ls command would have something that basic. The Amiga does:
Simple, easy to use and understand.
GNU
Additional:
I don't seem to be able to leave it alone. Here is a weird solution that I never would have thought of: use the bash shell's wildcard expansion to do it.
This has a couple of shortcomings, but as always,
We
I'm astounded that linux doesn't have an easy solution to this. Even crappy old MSDOS can do it.
Not very readable, but at least it does it.
Additional:
I have a commandline program called
Nice.
Found where I got it. http://mama.indstate.edu/users/ice/tree/
It was written by Steve Baker (ice@mama.indstate.edu) with HTML output capability Francesc Rocher (rocher@econ.udg.es) and character sets by Kyosuke Tokoro (NBG01720@nifty.ne.jp)
ls command is bound to have an option to restrict output to only directories, right? Wrong. This turned into quite a chase.After spending too long experimenting with various things I checked the net to see if anybody else knew the answer to what I was starting to think I was too stupid to see. It seems many other people have come up against this deficiency in the
ls command. There have been a lot of suggestions to get around it. The most common is: ls -d */but that has three failings. It prints the entire path, lists the directories with a trailing slash (the -d option), and doesn't see hidden dirs (those that begin with a dot). It is easy to use
sed to get rid of the trailing slash: ls -d1 */ | sed 's/\(.*\)./\1/g'and a little more fussing with
sed can get rid of the path, but I can't find any way to list the hidden dirs along with the normal ones.Another common solution is to use the
find command: find . -maxdepth 1 -type dThis works but puts all the output on one line, precedes each file with its path, the first line is always the name of the directory being listed, and the file list is all jumbled up. I can use the -printf option of file to fix the path problem and to put each name on its own line, getting rid of the first line is just a matter of piping through the tail command, and pipe through the sort command to organise the result.
find . -maxdepth 1 -type d -printf '%f\n' | tail -n+2 | sortThat took a lot more hassling than I expected. Weird. You'd think that the ls command would have something that basic. The Amiga does:
dir . dirsSimple, easy to use and understand.
GNU
dir command has a -d option supposedly to display only directories, but it doesn't seem to work properly.Additional:
I don't seem to be able to leave it alone. Here is a weird solution that I never would have thought of: use the bash shell's wildcard expansion to do it.
echo */This has a couple of shortcomings, but as always,
sed can help: cd "$address" ; echo */ | sed 's/\/ */\n/g'We
cd to the directory that we want to list from. The echo gets expanded to everything there that ends in a slash (all the directories), then sed looks for a slash followed by none or multiple spaces (can't just be a space because the very last slash doesn't have a space) and replaces them with a newline.I'm astounded that linux doesn't have an easy solution to this. Even crappy old MSDOS can do it.
DIR /A:D /B /O:NNot very readable, but at least it does it.
Additional:
I have a commandline program called
tree though I can't remember where I got it. I don't think it is standard on linux distros, but it has a lot of nice options, including the ability to print out a list of directories. It has one tiny failing, in that it begins the list with the name of the containing directory, but as before we can simply snip that off with tail: tree -ad -L 1 -i "$address" | tail -n+2Nice.
Found where I got it. http://mama.indstate.edu/users/ice/tree/
It was written by Steve Baker (ice@mama.indstate.edu) with HTML output capability Francesc Rocher (rocher@econ.udg.es) and character sets by Kyosuke Tokoro (NBG01720@nifty.ne.jp)
no subject
Date: 2012-05-26 04:38 am (UTC)I'll have to think more about your conclusion that money-as-value contains a logical contradiction. Cool.
I, rather perversely, like the awful inefficiency of some Turing machines. http://srimech.blogspot.com/2011/03/turing-machine-and-maker-faire.html is wonderful, even having a steam-powered version! Other, related, gadgets that tickle me are the lovely stuff that some people have built inside LittleBigPlanet, for example, http://www.youtube.com/watch?v=ursnIpTOPDQ which demonstrates a base-4 counter using that world's physics. Ludicrous fun!
Yes, I've heard the expanding balloon illustration, but that doesn't really explain anything. If space itself is universally expanding then we don't see any change, but if, as most people argue, gravity and electromagnetism, and the strong and weak forces all overwhelm the expansion when things are close to each other then it ends up explaining nothing. One might as well say that on the grander scale all things are moving away from each other, or that gravity works differently at great distances, or something else.
I do worry that I am quite possibly missing out on important parts of the universe by being mathematically inept. I love what I can see of maths, but struggle badly with it -- perhaps resulting by being terrorised by a math teacher when I was little and my dyscalculia.
I like what you said about quantum mechanics. I consider quantum mechanics to be like Boyle's Law, where Boyle was able to find reliable information about the pressure and volume of a gas without understanding anything of the essentially random nature of the molecules beneath. I think we are at a similar stage with quantum mechanics. We can make probabilistic measurements of, for instance, the electron "cloud" around an atom. At the moment it looks impossible to see any deeper than that, but I think that is likely to be just a limitation of our current toolset. In 20 or 30 years I fully expect some bright young thing to come up with a way of going "deeper". I hope I'm right... and I hope, though I doubt, that I'll still be here to see. Curse our brief lifespans! If I could live for a thousand years it still wouldn't be enough; a bare 80 or 90 is painfully, miserably short!
I hope I'm not getting True Names mixed up with another story, but wasn't it the one where a guy gets infatuated with a young girl and lures her to a motel by pretending to be a boy of the same age then attempts to seduce her? It may be that it was only a small part of the story, but it left me with a strong feeling of revulsion at the time which probably discolored my view of the story. A pity. I have great respect for Vernor Vinge.
Scientology tries to differentiate itself from other religions, but in the end it revolves around insubstantial, supernatural spirits, making them the same as all other superstition. Using alien spirits is an example of the common religious trick of distracting people's attention with irrelevant info.
no subject
Date: 2012-05-26 02:06 pm (UTC)Though there are serious problems with the standard cosmologies, the problems you have with them are not among those serious problems. But to explain why your objections are invalid, I will have to use some math. Analogies won't do; they can only convey flavor without substance.
Science is full of good models, QM and Boyle's law among them. Science has since successfully explained why Boyle's law works but has yet to explain QM. It sure would be nice to see that explanation....
It's rather frustrating to know that I'm right at the cusp—were I even a decade younger it's a virtual certainty that I would be able to surf the wave of ever improving life extension techniques and thereby not have to expire of old age. Ah well, reality is.
I think you've got "True Names" mixed up with another story. It's worth a read, not just for the story, but for its historical value.
I don't know enough about scientology to know whether its "aliens" are merely supernatural spirits in disguise. And, frankly, I'd rather spend my time cleaning a cesspool than look into the matter. I merely give them the benefit of the doubt (as silly as that may be) by assuming that they're not supernatural.
It turns out that the video programs you mentioned are all ported to FreeBSD. I was able to download them from a standard location. However, I'm an untrusting soul and so I've got to figure out a way to run those programs without giving them a chance to infect my system.
no subject
Date: 2012-05-27 02:01 am (UTC)Yes. I too feel the frustration of likely being at the cusp of potential immortality. All we can hope is that humanity progresses, preferably faster than at present and that the demons of superstition are dispelled soon. On both points I'm hopeful, but somewhat pessimistic.
Okie dokie. I found True Names among my books and took a brief look at it. I no longer think I've read it so have added it to my enormous to-read stack. It occurs to me that I may have been mixing it up with a vaguely recalled novel about VR by Ben Bova.
...rather spend my time cleaning a cesspool than look into [scientology]...
heheheh :D Yes. Some time back I started reading, with mounting annoyance and impatience, the story of Xenu that the scientologist suckers swallow. I couldn't read the whole thing. It was such a dopey fantasy.
no subject
Date: 2012-05-27 03:13 am (UTC)As for whether happiness is a final value or a means to survival, that depends on how one chooses. Some will decide to make happiness their final goal; others will decide to seek it as a means to an end. I'm in a third camp: One should not pursue happiness as such. Rather, one should pursue certain other values and one's happiness will be one signal of one's success at that pursuit.
The main hope for those of us on the cusp is that the growth of knowledge is at least exponential. Then again, what with government meddling in the biological sciences, there's a damned good chance that important research will be stifled by religiously inspired "ethics". i have little hope that people will abandon that idiocy.
Ah, Ben Bova. He's OK but he writes too mainstream-like for me.