While there are certainly some people who will pick apart examples like these and learn new tricks, I've seen enough copy-and-paste programming to know that many won't.
While there are certainly some people who will pick apart examples like these and learn new tricks, I've seen enough copy-and-paste programming to know that many won't.
$ ls | grep -e .*5.*
Would be better as: $ find . -name '*5*'
or if you insist on using a regex: $ find . -regex '.*5.*' $ ls *5*
??The find command is more powerful (descending into subdirs, etc.), but the original example in the link only specified the current directory.
$ ls -d *5*
Otherwise you get a listing of any directory with a 5 in the name. ls *5*
will fail because the argument list was too big for execve(2). Would I design it that way? No, but people do (sometimes without really thinking about it), and you still have to get work done.New users should be taught find(1) because it always works.
However, in the example in the article, he was using "ls" piped to "grep" in order to find all files with a 5 in the name. That would suffer from the same consequences you mentioned, on such systems, and is inefficient and verbose.
Note, I agree with your advice to teach "find" (and "xargs") to users.
ls | grep 5
is reliable where ls *5*
is not. (Well, except for awful names that require "find -print0", or preferably having the file taken out and shot along with its creator.)I'm actually not a fan of xargs. It's more unixy, but somehow I find its options hard to remember. Off the top of my head I find it easier to do
find -exec blah {} +