5 ms·
> Just try these in Bash or PowerShell! > select fullpath from files where fullpath like '%sublime%' and fullpath like '%settings%' and fullpath not like '%back
by jewel 11y ago
> Just try these in Bash or PowerShell!
> select fullpath from files where fullpath like '%sublime%' and fullpath like '%settings%' and fullpath not like '%backup%';
This isn't a very good example, because it's trivial to do in bash:
locate sublime | grep settings | grep -v backup
(Replace `locate sublime` with `find / | grep sublime` if locate's results are too old.)
> select fullpath, bytes from files order by bytes desc limit 5;
This is better. Here it is in bash:
find / -type f -exec stat -c '%s %n' {} \; | sort -nr | head -n 5
Cherry picking another one that stood out to me.
> select writeln('/Users/SJohnson/dictionary2.txt', data) from fileslines where fullpath = '/Users/SJohnson/dictionary.txt' order by data;
cd /Users/SJohnson/; sort dictionary.txt > dictionary2.txt
Some of the rest of the examples are trivial in bash, and others look potentially useful. Of course they are trying to demonstrate its capabilities so the examples are contrived. I can see how this would be useful for someone who doesn't know the command-line, but as someone who is proficient in both SQL is pretty verbose.
In the real world I'd switch to a scripting language for some of the more complex cases, since they'd be rare.
- untog 11y agoSure, if you already know all that. But select fullpath, bytes from files order by bytes desc limit 5; is infinitely more readable/parseable than: find / -type f -exec stat -c '%s %n' {} \; | sort -nr | head -n 5 Just something exists doesn't mean it isn't an incomprehensible pile.
- hobs 11y agoI think powershell still isnt really that hard for this (and was mentioned earlier) Something like: gci / -recurse | sort fullname | select fullName, length -first 5 Really doesnt seem that hard in comparison.
- untog 11y agoAgreed. It's interesting - last time I looked at PowerShell it seemed insanely verbose, but maybe I was looking at some odd examples.
- hobs 11y agoOh, it can be. The confusion lies around the fact that you can do basic things half a dozen ways, and I also used some shorter aliases (eg Get-ChildItem (or gci, or ls) Sort-Object (sort) Select-Object (select)) You can sort of choose what level of verbosity you want to encode in your scripts for your sanity at a later date.
- WorldMaker 11y agoAs pointed out a lot of the verbosity in PowerShell is optional these days as there are a good number of aliases for common commands. The nice thing about the verbosity is kind of similar to the point of SQL in that it too has something of a natural language DSL intent (in PowerShell commands are expected to be "Verb-Noun" and verbs for the most part are encouraged to be from a relatively small set of common verbs). This can make it a bear to fully write out without an IDE (and there are multiple choices these days) or tab completion (which gets better with each release). The benefit however, is that typically you can very easily read someone's PS1 script if it has been written at full verbosity and know what it is doing. It's often very close to self-documenting at that point.
- andmarios 11y agoNot really. If you write SQL statements for a living, the former is more readable, if you sysadmin for a living, then the latter wins. A sysadmin will use tools like find, sort and head very frequently, whilst SQL statements will be fairly rare.
- blowski 11y agoThey are both technical, but 'order by bytes desc' has got to be more expressive than 'sort -nr'. It's almost natural human English, whereas the latter doesn't express anything. That said, I don't know how much time it would genuinely save. As with most of these tools, you shouldn't be installing them on production servers, so you still have to know Bash anyway.
- cogs 11y agoCrab has tab completion, so there's not too much extra typing, and the repacement of hieroglyphics by words does help readability. It's especially handy to see what is going on if you wrote it a month ago, and don't remember all the command line switches.
- zeckalpha 11y agoExcept Crab isn't as old as find. Find is likely to be around in 20 years.
- mb0 11y agofind / -type f -iname 'ASTERISKsublimeASTERISK' | grep -i settings | grep -v backup
- gioele 11y ago> > select fullpath, bytes from files order by bytes desc limit 5; > This is better. Here it is in bash: > find / -type f -exec stat -c '%s %n' {} \; | sort -nr | head -n 5 This is also a nice example of the biggest problem piped shell commands: each command is executed in isolation. Because of that you miss on many optimizations that are possible when you know the full query.