Live data from Hacker News

A common mistake involving wildcards and the find command

blog.robertelder.org

141–148 of 148 posts

Re: A common mistake involving wildcards and the find command

#141

Phew! I'm glad I've been hitting the "Happy Case" scenario all these years! Very useful article. And very informative. Summary: Instead of - find . -name *.jpg Use quotes around pattern i.e. find . -name '*.jpg' Edit: Oops, the double-quotes should have been single quotes! Thanks, @lucd. Happy case, like I said!

[deleted]

Re: A common mistake involving wildcards and the find command

#142
post #26

For a long time (probably since the first time I forgot to quote something and got burned, so around 40 years), I've thought that there should be some mechanism for the shell to pass in information about how each argument came about. For each argument, it would tell the program if it was supplied directly, or came from wildcard expansion. For those from wildcard expansion, it would tell the program what the wildcard…

it's trivial to set this up yourself by echoing expanded commands into a log file as your program runs

Re: A common mistake involving wildcards and the find command

#143

Quiz; in any directory, full or empty I can run this command $ * and get * What allows me to do this? (the $ is the prompt, not what I typed)

GLOBIGNORE=*; *(){ echo *; } welp

Correct! More or less. Mine uses alias rather than a function.

    alias \*='set noglob; echo \*'
Works because alias expansion is done before globbing.

Re: A common mistake involving wildcards and the find command

#144

Earlier quoted context omitted.

I think there is a cottage industry around telling people that they're using the interactive shell wrong. This all started with "useless use of cat", which people still bitch about on Reddit and Twitter on a regular basis, and so whenever someone finds something a little weird about UNIX, they are quick to call a person asking a question about it dumb. I think it might be stockholm syndrome, or a symptom of one's gre…

> Bad design is that find uses \n as the output record separator and that xargs uses \n as the input record separator, but \n can appear in filenames! This design can never work and will always lead to difficult-to-debug problems. So instead of fixing it Perhaps, but it also can't be avoided. Everything can appear in filenames. We want filenames to be able to contain any character. The most high-profile attempt to "f…

There are two options. \0 can't appear in filenames, which is certainly questionable (why is that byte special?), so using \0 as the separator works. A better way of solving the problem is to just prefix the record with a field that represents the length. People are allergic to the length prefix because, say you set it to 2 bytes, now your max file length is 512 characters AND you have two bytes of overhead for every filename. Whereas using \0 means that you have only one byte of overhead and can have infinitely long filenames.

Interestingly, I guess nobody has ever died because of a buffer overflow. Therac-25 was integer overflow and bad synchronization (and an open loop control system, which people still love). So I guess it doesn't matter.

Re: A common mistake involving wildcards and the find command

#145
post #138

Earlier quoted context omitted.

For me, Silver Searcher often fails to find matches in files that 'grep' will, easily. I've not been able to determine why this is, but it happens often enough that I consider SS to be highly unreliable, even if its fast. So, it seems that there are still some issues to be sorted here.

This claim needs adequate proof, please provide an example. Otherwise the HN reader has to assume you made a user error.

Maybe it has something to do with my not understanding its case sensitivity rules .. which I've learned about in this thread as being different.

As soon as it happens again I'll bring it here as an example, but like I said I stopped using silversearcher because of it getting in my way like that.

Re: A common mistake involving wildcards and the find command

#146

Earlier quoted context omitted.

You can't, at least on bash version 5.0.3(1)-release with the default config Ubuntu packages it with. After a lag I get the error `$folder_name$: command not found`

I promise you you can, with a previous particular incantation. Answer to come. PS. the response is not important.

Oh, I thought you meant in an arbitrary directory. If the first file in sorted order is executable and prints "*" to stdout you could get that.

Re: A common mistake involving wildcards and the find command

#147

Earlier quoted context omitted.

Tip: get into the habit of using && rather than ; So... > ssh remote 'cd /whatever && tar -cf - someglobpattern' | tar -xvf

Seconded. Here https://apple.stackexchange.com/questions/378942/cant-initia... is an example of what can happen from not checking for errors after a `cd` command. Summary: "sudo find ... -delete" ran in the root directory rather than the intended location, and now the OS is gone (probably along with lots more).

Fair observation. I will change my ways :)

Re: A common mistake involving wildcards and the find command

#148

Earlier quoted context omitted.

I promise you you can, with a previous particular incantation. Answer to come. PS. the response is not important.

Oh, I thought you meant in an arbitrary directory. If the first file in sorted order is executable and prints "*" to stdout you could get that.

I did mean an arbitrary directory.

Your answer almost works; but only if PATH includes the current directory which is unusual.

It does hint at another almost answer ...

   mkdir t
   cd t
   ln -s $(type -p ls)
   *
Post reply on HN