But I think echo *.py would not just be easier, but more effective at demonstrating what your find command line will actually look like after shell expansion.
A common mistake involving wildcards and the find command
41–50 of 148 posts
Re: A common mistake involving wildcards and the find command
#42Re: A common mistake involving wildcards and the find command
#43Translation: you cannot type "man" followed by an asterisk because that would have required forethought in how one learns a programming language.
Argle: Hey Bargle, is that new bridge built to spec?
Bargle: It's like I always say, man: good enough for shell script manual operator discoverability.
Argle: Yeah, you're always saying that...
Re: A common mistake involving wildcards and the find command
#44Re: A common mistake involving wildcards and the find command
#45Another one I've seen a few times with find (although it is actually more an xargs thing than a find thing), usually not with any bad consequences at least, is something like this: find . -type f | xargs grep foo You expect to see all the "foo" lines from your files, each prefixed with the file name and a colon. And that's what you get most of the time. But sometimes you might get a foo line without the filename pref…
A “better” fix would be: find . -type f -exec grep -H foo {} +
Re: A common mistake involving wildcards and the find command
#46Tangential: another safeguard you can adopt is avoiding "hard delete" commands like rm and find -delete. Untrain yourself from these commands by never using them. On Mac systems, the "trash" program (brew install trash) sends files to your system trash. You can use `trash [file]` and `find .. -print0 | xargs -0 trash --`. rm is a dangerous command you should only very rarely be using. I fish something out of the tras…
Re: A common mistake involving wildcards and the find command
#47This was obvious to me, but one version of this that surprised me is when using scp. If you glob a remote destination like "scp myserver:*.jpg ./" It will probably work! But how? Because the remote path will likely not match any local files and the path with the asterisk will be passed to scp and scp will do the globbing on the remote side.
I mostly use ssh and tar instead of scp, because I'm usually after more than one file. Like, "ssh remote 'cd /whatever; tar -cf - someglobpattern' | tar -xvf"
So...
> ssh remote 'cd /whatever && tar -cf - someglobpattern' | tar -xvf
Re: A common mistake involving wildcards and the find command
#48$ *
and get
*
What allows me to do this? (the $ is the prompt, not what I typed)
Re: A common mistake involving wildcards and the find command
#49Quiz; 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)
Re: A common mistake involving wildcards and the find command
#50Earlier quoted context omitted.
A “better” fix would be: find . -type f -exec grep -H foo {} +
Yeah, find ¦ xargs is definitely an antipattern, but in practice I use it all the time. Either because I forget the syntax for find -exec, or because I'm feeling principled that find -exec breaks the Unix philosophy of doing one thing well and being composable, or because my script started using ls and got changed to use find.