miriam_e: from my drawing MoonGirl (Default)
miriam_e ([personal profile] miriam_e) wrote2012-05-10 01:00 pm

listing dirs on the commandline -- not so simple in linux

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 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 d
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.
    find . -maxdepth 1 -type d -printf '%f\n' | tail -n+2 | sort

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:
    dir . dirs
Simple, 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:N
Not 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+2

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)
twwells: Me, circa 2000. (Default)

[personal profile] twwells 2012-05-24 08:40 am (UTC)(link)
I use FreeBSD rather than Linux, so some commands are different. However, the pipeline find -s . -mindepth 1 -maxdepth 1 -type d | cut -c3- does what you want on my system and it ought to work on Linux.

BTW, I got here via one of the atheism communities; I was searching for philosophy but there doesn't appear to be much of that on dreamwidth.
twwells: Me, circa 2000. (Default)

[personal profile] twwells 2012-05-24 07:23 pm (UTC)(link)
Find -s does sort the entry though, as you note, piping through sort does as well.

Although I'm an atheist, I don't have much to say about atheism; I hold that a word that supposedly denotes something for which there is no evidence has no meaning. Thus, anywhere one puts the word "God", one could put the word "unicorn" and one has said the same thing—the same nothing. Have you read George Smith? I think the relevant book is "Atheism, the Case Against God".

Right now, I'm not set up to do video. It's a low priority for me, since I'm very, very nearsighted and don't particularly enjoy moving pictures of any kind.

I'll look at the other items in a bit.....

twwells: Me, circa 2000. (Default)

[personal profile] twwells 2012-05-25 04:53 am (UTC)(link)
Forgive a bunch of nitpicking but I figure that if I don't write it all down now I'll forget it and some of it might be of value to you. I'll do a real reply after I've got this out of the way....

I was looking through your site (I read nonfiction of interest and a few short fiction pieces) and noted a few minor items. I use a browser called dillo that nitpicks sites. It complained about the DOCTYPE on your home page and noted a missing # on line 14 in a color specification. Also, the value monoculture link on your waffles page is broken. Might be other stuff but I wasn't actually looking for HTML nits. :)

I looked at some of your comments on gravity and the big bang. I think you have some fundamental misunderstandings about the science. (I studied those things, oh, about 40 years ago, so I'm rusty. But I could try explaining....) Turing did not prove that a computer can simulate anything. What he actually proved is very technical but it is essentially the proposition that any general purpose computer can simulate any other general purpose computer. However, there are many things that a Turing machine cannot simulate, including (in general) analog objects. A brain being analog, there is no reason to suppose that it can be simulated on a computer. All that a computer might be able to do is simulate a digital approximation to a brain. But chaos effects might make such a simulation have no relationship to how an actual brain functions. I doubt there's any way to tell if a computer can simulate a brain other than by trying it out.

Enough nitpicking....

Androids and humanity: Have you read Jack Williamson? If memory serves, he wrote a short, "With Folded Hands", which he expanded to a longer story, "The Humanoids". There were sequels. They dealt with robots dedicated to mankind's well-being. They're old science fiction. :)

Way back when, I wrote an essay that argued that strong AI isn't possible in the sense most people wish. As I see it, true AI is only possible to a living (not necessarily organic) entity and thus a true AI would be an intelligent, valuing being—human in every sense that matters, even if it's software on my PC.

Speaking of VR and old (well, not so old) SF, have you read Vernor Vinge's "True Names"? It's arguably the first VR story.

Well, I don't actually have any problem with the word "atheist". It's merely a way to categorize people: some people think there is a god (whatever they might mean by that) and some don't. Since "theist" and "atheist" refer to actual existents, people with particular beliefs, they're legitimate words. As you note, there are many connotations to those words and calling oneself an atheist might be a bad idea in some situations but there's nothing irrational about the word itself.

"God" is an entirely different kettle of fish. The problem is illustratable by contrasting, "There is an elephant in the room" with, "There is a unicorn in the room". In the former, we have a proper concept, "elephant", and can (in theory) enumerate all the objects in the room and say that each one is or is not an elephant. We can thereby prove or disprove the proposition that there is an elephant in the room.

However, "unicorn" is a made up concept. It doesn't refer to anything. We can never really say, even in theory, if there's a unicorn in the room. Give this amorphous notion one definition and the answer might be yes; give it another and the answer might be no. The question can't be answered because there is no actual answer to it. The underlying cause is that reasoning is ultimately about real things. If made up words are put into a sentence and then reasoning rules are applied to the sentence, the result may have the form of reasoning but it is not real reasoning. So it is with any discussion about "god".

It is only when "god" is given substantive content, a meaning that refers back to real existents, that it becomes possible to meaningfully reason about "god". So, for example, you can point to reality, which certainly exists, and define "god" as, "that which created reality". Doing that allows a minimal kind of reasoning about "god" but, as you noted in one of your essays, that reasoning leads to the conclusion that the existence of reality is not evidence for the existence of "god". So it goes for all the various attempts at defining "god"; in each case, the end product of the reasoning says that there is no evidence for the existence of that particular sort of "god".

What George Smith argues is the essential reason for that conclusion, and why that conclusion must be reached for any type of proposed evidence for "god": Concepts that refer to the supernatural invariably involve self-contradiction. (That's my language, not his.) I'll leave that discussion to his essay.....

In describing the religious as delusional, I imagine that you meant that metaphorically. But I think that it's a reality. Once one drops the idiotic notion that a widespread delusion isn't a delusion (see, e.g., Wikipedia's article on "Delusional disorder"), religious belief looks pretty much like any other delusional system.

BTW, I pulled that youtube script off the net and we'll see if it works on my machine. I have plenty of bandwith but my computer is ancient; it barely runs firefox and will not run firefox with any plugins (it goes to swap Hell). But I can pull down a video and then use a stand-alone video player. We'll see how it goes.....
twwells: Me, circa 2000. (Default)

[personal profile] twwells 2012-05-25 02:48 pm (UTC)(link)
I have dillo, firefox, and lynx, and use them in that order of frequency. Which goes to prove that utility does not equal quality, because that is the inverse order of their quality! Dillo is really buggy but it has the combination of features I need. Firefox has plenty of bugs (and uses far too much memory) but it does javascript and it's the one that too many my-HTML chauvinists code for. Lynx has no bugs that have caused me problems, but only renders text. So, I just pick the right tool for the job, which usually turns out to be dillo.

I disagree with the notion that values are intrinsic. Values are always relative; to say that something has a value one must implicitly or explicitly have a particular thing that values it This doesn't invalidate your value monoculture essay. If anything, it strengthens it. If a value is always relative to that which has the value, it is impossible to make your values and mine commensurable. Yet, on the money-is-the-only-value theory, money is a common denominator for all values. Thus the money monoculture can't work, because it is based on a logical contradiction.

A Turing machine is a very simple kind of computer. Turing invented it because it is mathematically tractable. What he proved is that a Turing machine can simulate any digital computer. And, since it is trivial to make a real computer simulate a (finite) Turing machine, one can simulate on one computer a Turing machine that simulates another computer. Thus, any computer can simulate any other computer. The obverse of a Turing machine's mathematical tractability is that it is horribly inefficient; you would not want to try to simulate an adding machine on one (except for fun), much less a brain. However, if a brain can be simulated at all, you could simulate it on a Turing machine.

I note that, even if the brain is digital, it can still be chaotic (and almost certainly would be). If so, it might turn out that it's possible to create an artificial mind but not to upload to one, because of unavoidable measurement errors.

Here's an answer to your "expanding balloon" objection. Think of objects as raisins embedded in the balloon. Only the rubber expands; the raisins don't. I should point out that all of these analogies are essentially worthless if one wants to really understand what's going on in cosmology; they capture the flavor of the science but almost nothing of its substance.

If you have a taste for math, it would profit you to look into Riemannian geometry, since that's the math that General Relativity is based on. If math isn't your thing, I can attempt to provide analogies that answer your other objections.

I make a distinction beyond the hypothesis/theory dichotomy you mentioned. A theory is, in essence, a relationship between facts. A model is a method of prediction. Ideally, a theory is also predictive but it doesn't have to be. Conversely, a model is ideally based on a relationship between facts but it doesn't have to be. One of my objections to modern science is that it conflates the two, and insists that a science that isn't predictive isn't science. I can sympathize with the reasons for that insistance but I can't agree with it.

Quantum Mechanics proper is a model because it is agnostic about the underlying reality. Only if one adds to QM some interpretation, such as Copenhagen or Many Worlds, does one have a theory. Why is this important? A theory, if true, tells us something about reality. Models don't. However useful a model is (and QM is very useful), it can't tell us anything about how reality actually works. So all of those claims that reality is "really" random because QM uses randomness in its predictions are simply wrong. Such a claim would only be arguable if QM were a theory, but it isn't.

What did you find creepy about "True Names"? I did read "Permutation City" but I didn't like it. There were two reasons. First, I didn't find the ideas particularly new. Second, my main interest in stories is to read about characters I enjoy spending time with and I didn't get that from the book.

When talking about "god", it's very important to distinguish two very different concepts. Most religions are based on the supernatural, a realm that differs from the natural by having no fixed nature. Scientology and the "aliens as creators" hypothesis are altogether different, in that they don't suppose anything supernatural. The arguments against the two are different, not just in details, but in kind. In the former, the arguments stem from the logical incoherency of the notion of the supernatural; in the latter, the arguments are fact-based, and amount to some variation on "there is no evidence whatsoever for that hypothesis, so it need not be considered".

I'll look at those video players; if they run on Linux they can almost certainly be run on FreeBSD.
twwells: Me, circa 2000. (Default)

[personal profile] twwells 2012-05-26 02:06 pm (UTC)(link)
I think the distinction you're trying to make is between values that are means to an end and those that are not. Most values are means to an end. I don't buy food "just because"; I buy it so that I can eat it. Food is a value to me because it enables me to eat. Happiness, as you see it, is different from food, because you don't seek out happiness for any particular purpose; you experience happiness directly as valuable and so do not need any other end to justify seeking it out. Is that correct? (I should note that I don't see happiness as an end in itself. But that's whole 'nother discussion. :))

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.
twwells: Me, circa 2000. (Default)

[personal profile] twwells 2012-05-27 03:13 am (UTC)(link)
It might not be a good idea to call values that are ends in themselves "intrinsic", as that word generally has a different meaning. Head over to The Free Dictionary to see what I mean.

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.