15 ms·
In defense of Unix
- knz42 11y agoThe article could have been enhanced by highlighting that some shells (e.g. zsh) provide expansion patterns that recurse into subdirectories. e.g. ls **/*.txt
- nothrabannosir 11y agoor in bash, with the globstar option set: shopt -s globstar # e.g. in your .bashrc ls **/*.txt
- mnarayan01 11y agoIt's probably worth noting that the option is new in 4.0 -- relevant as OSX users are likely on 3.0.
- paulddraper 11y ago3.0 is ancient, but 4.0 is GPLv3....
- ahoka 11y agoThis thread perfectly sums up what's wrong with Unix.
- avar 11y agoApple not wanting to distribute software that they're perfectly able to distribute for paranoia/anti-GPLv3 reasons is a problem with Unix?
- yrro 11y agoWe're blaming "Unix", whatever means, for the stupid decision by one UNIX® vendor to stop shipping updated versions of the tools that form the core of the operating system? :)
- microcolonel 11y agoIn fish at least, I'd just use ls **.txt
- escherize 11y agoThanks for the tip!
- zokier 11y agoIn my opinion ls is one of the more broken bits in unix. But besides that, arguably more unixy way (even if no proper UNIX supports it out of the box) to solve is recursive wildcard, i.e. ls **/*.txt
- deleted 11y ago[deleted]
- twic 11y agoI'd say this is less unixy, because it relies on the shell to walk the file tree, rather than delegating to a utility whose job is to do just that. No comment on whether it's actually better or worse, mind!
- OJFord 11y agoI was going to make a similar argument, but then I lost faith in what ls' job is, if we want to walk this really pedantic path. After all, `echo * * / * ` is going to give you an ugly dump of space-separated files; while `ls * * / * ` will give you a pretty list with colours, ownership, permissions, date modified, is directory/exec/symlink, etc. with their respective flags or according to your alias. I don't think it's cheating to argue that `ls` job is to format the files given, or within given directory. Edit: Although possibly it is, because `man ls` tells us "list directory contents".
- julian-klode 11y agobash supports that, just do shopt -s globstar to enable it.
- DiabloD3 11y agoA lot of what this article talks about is why systems like msys2 exists: to bring a *nixy command line to Windows.
- bitwize 11y agoOnly useful for compiling software that depends on Unix toolchains. Modern Windows has PowerShell, which is leagues ahead of bash in terms of functionality and power.
- DiabloD3 11y agoNot really. I use msys2 every day, and I've never used it to compile things. And PowerShell is kind of useless since I can't use it on any other computer I interact with on a daily basis. I use a github-synced environment, that includes things such as my zsh and vim configs.
- Gratsby 11y agofunction dir(){ #make the windows guy happy find ./ -type f -name "$1" }
- yrro 11y agoBut... there's already a dir command... https://www.gnu.org/software/coreutils/manual/html_node/dir-invocation.html https://www.gnu.org/software/coreutils/manual/html_node/dir-...
- Gratsby 11y agohrmph. I never knew about it.
- yrro 11y agoNot trying to be cheeky, but I have genuinely found it very illuminating to read the _proper_ documentation for all the GNU software that I use. Not the man pages, but the documentation available 'online' via info, and 'offline' on the web for those who are info-phobic. :) When I find my mind wandering and I am tempted to waste time on reddit/Hacker News, I try to discover a new feature, or a new aspect of one with which I thought I was already familiar. The info program (hated it when I first used it, now I prefer to use it to access the documentation of stuff that I have locally installed): https://www.gnu.org/software/texinfo/manual/info-stnd/info-stnd.html https://www.gnu.org/software/texinfo/manual/info-stnd/info-s... Readline User Manual (that thing you use when you press Ctrl-R to search your Bash history): https://tiswww.case.edu/php/chet/readline/rluserman.html https://tiswww.case.edu/php/chet/readline/rluserman.html Findutils (the find and locate commands): https://www.gnu.org/software/findutils/manual/html_node/find_html/index.html https://www.gnu.org/software/findutils/manual/html_node/find... Coreutils (ls, rm, sort, tail, tee, the good stuff): https://www.gnu.org/software/coreutils/manual/coreutils.html https://www.gnu.org/software/coreutils/manual/coreutils.html glibc (an incredible manual that is very readable): https://www.gnu.org/software/libc/manual/html_node/index.html https://www.gnu.org/software/libc/manual/html_node/index.htm... Bash (actually has a good man page, but it's nowhere near as in depth as the reference manual, nor does it explain features with language designed for those who don't know that they already exist): https://www.gnu.org/software/bash/manual/html_node/index.html https://www.gnu.org/software/bash/manual/html_node/index.htm... Groff (have you written a man page for the last program you wrote?): https://www.gnu.org/software/groff/manual/html_node/man.html#man https://www.gnu.org/software/groff/manual/html_node/man.html... Gcc: https://gcc.gnu.org/onlinedocs/gcc/ https://gcc.gnu.org/onlinedocs/gcc/ GNU Make (bet you didn't know you could extend it with Guile and native code...): https://www.gnu.org/software/make/manual/html_node/index.html https://www.gnu.org/software/make/manual/html_node/index.htm... Automake (for many years the autotools were something deeply mysterious to me that I thought I'd never understand, then I read the manual for them and now I can't get enough of them, and the shortcomings of other build systems cause serious pain): https://www.gnu.org/software/automake/manual/html_node/index.html https://www.gnu.org/software/automake/manual/html_node/index... Autoconf: https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/index.html https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/a... libtool: https://www.gnu.org/software/libtool/manual/html_node/index.html https://www.gnu.org/software/libtool/manual/html_node/index.... The C Preprocessor (has its own manual, who knew!): https://gcc.gnu.org/onlinedocs/cpp/ https://gcc.gnu.org/onlinedocs/cpp/
- txutxu 11y agoThe post linked from this article says: Great. It is spread everywhere this kind of complication for everyday tasks. Want to install something, need to type: apt-get install something Since we only use apt-get for installing stuff, why not? apt-get something I will give a response I didn't see in any comment there, in the original post, neither in this post or here: Because it could fail miserably trying to install like this, any package named like a subcommand. apt-get remove # is installing package remove? # or is failing the remove subcmd without args You can workaround that, by apt-get install remove in that case, but the error at first try is counter-intuitive. Edit: fix my last example
- nunobrito 11y agoOriginal post author here, Nuno Brito Except that exists no package named "remove" available today in mainstream Linux.. So we are forcing every single user across decades to use "install" because a "remove" package is prophesied and we couldn't reserve this keyword. Well, that's XKCD material.. :-) But without playing: If you see the current syntax as good enough, that is OK. The point is usability on upcoming command line tools.
- talideon 11y agoYou'd just be replacing one inconsistency with another: you couldn't use any command names as package names or the reverse without some kind of special case, which would be just as bad. The real solution would be to get rid of the split between apt-get, apt-cache, &c., which is a real UI issue, and just use a single 'apt' command. Then you'd have 'apt install package' - two of the usability issues with 'apt-get' go away if you do that: the need to use a bunch of other tools for no good reason and the '-get' wart at the end. And guess what: that happened in Debian and its derivatives a fair while ago. It's just that nobody made a big deal of it. Here's the relevant section of the handbook: https://debian-handbook.info/browse/stable/sect.apt-get.html https://debian-handbook.info/browse/stable/sect.apt-get.html
- phillc73 11y agoAgreeing with you. apt-get purge apt-get autoremove apt-get update apt-get dist-upgrade Plenty of other uses for apt-get besides install.
- exprx 11y agoThe mentioned blog post is horribly ignorant, and lacks almost any valid points. find, in particular, very much has a fine UI, and I dare you to process, and not just list, the files with cmd.
- jstimpfle 11y agoI do like find's UI as well. As an aside, I remember reading an article about how "the original Unix guys" found the syntax somewhat odd when find came about. But the command was useful enough that they kept it. (The article was about how inconsistent the Unix commands are regarding syntax, and I think its conclusion was that it is much more important to design syntax to fit the problem than to maintain a superficial consistency with other commands).
- Amezarak 11y ago> find, in particular, very much has a fine UI, and I dare you to process, and not just list, the files with cmd. I'm not really sure why he is comparing find with cmd in the first place. Nobody thinks cmd is good; most anybody actually doing anything in a shell on Windows would be doing it in Powershell. In that case, I would do something like: Get-ChildItem pathname -Filter test.txt -Recurse Any processing I want to do is easy, because I'm getting back objects and not just text. Say that I want to get a hash of each file named test.txt. Get-ChildItem C:\Users\Amezarak -Filter test.txt -Recurse | Get-FileHash
- ygra 11y agofor /r "C:\some path" %F in (*.exe) do process "%F" forfiles also exists, which works similar to find regarding passing the list of files to another command.
- raldu 11y agoI cannot see how this article is defending UNIX only by talking about a single utility. It could be a better "defense" if it mentioned, for example, the power of being able to compositionally combine various commands through pipes, each of which doing one thing well. Inputs and outputs, remember? The post the author is responding to is uninformed, and seems rather like a rant. DOS vs UNIX comparison does not work. I couldn't know how to take the `apt-get` example seriously. Because you could easily fix something like `alias ai='sudo apt-get install'` to achieve `ai something` magic with something as simple as aliases, which DOS does not even provide.
- bpye 11y agoPowershell also has pipes, and works with objects rather than with text. It can be very powerful and much easier than having to use awk, sed, etc.
- iLemming 11y agoand in the last example he given, i think you don't have to wrap things in quotation marks if alias done like this: alias lsr='find . -name $1'
- jstimpfle 11y agoThat doesn't work the way you think. Aliases don't receive arguments. The $1 will be expanded to the first positional argument of the surrounding environment when you call the alias -- not the first argument of the alias invocation.
- pdkl95 11y agoAs jstimpfle mentioned, that doesn't work, which is why the argument is left off the alias. In general, you can do that in a function instead of an alias: lsr() { find . -name "$1" } Wrapping variable expansion with double quotes is a good habit, so spaces are handled properly. Also, if you are using a modern-ish bash, you almost always want to use "$@" when there could be multiple arguments. The double-quoted @ special variable is guaranteed to always expand as multiple args, but with spaces handled correctly: foo() { bar --quux=42 "$@" } foo "a b c" "Spaces in my filename.txt"
- Vieira 11y agoAsk your parents or non-geek friends: Given the task of finding the files with the name ending with .txt which of the following two commands would you choose? find -name "*.txt" dir *.txt /s
- tonyedgecombe 11y agoNeither, they would search in Finder or Explorer.
- agumonkey 11y agoIt's funny how minds differ. As a kid I was mesmerized by globbing and pipe operators. GUIs didn't have the same magic appeal. The List monad was calling me from the future past.
- DanBC 11y agoHow about if you just give them the man page for "find" and the /? page for "dir" and see who can get the command correct first?
- mc808 11y agoLooks like "find" is yet another command with the Examples section at the very bottom. I suppose that's the convention or something, but sometimes I do run into a man page with the examples at the top, and it takes a lot of effort not to jump up and shout "Thank you!" loud enough for the author to hear me. The brain is a powerful inference engine. A few well-chosen examples can teach 95% of normal people 95% of what they need to know (numbers pulled out of my butt, 2016). Put good examples at the top and marvel at how many more people actually seem like they RTFM.
- deleted 11y ago[deleted]
- hasenj 11y agoI actually do this instead: find . | grep "\.txt$"
- jkot 11y agoI dont think its fair to mention DOS in 2016. There is PowerShell, VBS scripting etc...
- catnaroek 11y agoThere are good things about the Unix shell, but the fact that the shell, not the program being called, expands wildcards, ain't one of them.
- yrro 11y agoI like consistent and predictable rules for how wildcard arguments are expanded. There's no way that thousands of programs would all get it right if it were up to the developers themselves! That said, it would perhaps have been nice if glob expansion would have, in some other timeline, been performed by a separate command, so that «echo 🞳» would print out a literal 🞳 character, and «glob echo 🞳🞳» would print out the result of the expansion. glob could then accept flags to modify the rules for expansion, such as enabling the common shortcut for recursive expansion, rather than the user having to modify the behaviour of wildcard expansions by setting global variables.
- alkonaut 11y agoThis. I can't understand why it's handled at the shell level rather than at either the OS level (some Api to expand) or as a separate system tool? What happens if I make a shell that does expansion slightly diffrently to the existing shells? That can't work well? So there is already a set of rules for expansion and all shells must implement them exactly? That does sound just slightly better than the apps trying to do the same thing?
- yrro 11y agoIf programs had to use an API to expand paths then developers would screw it up. Just look at the clusterfuck that is the command prompt on Windows! In theory this applies to shell developers as well; however POSIX specifies how expansions should work, and there are far fewer shells than there are programs that those shells launch; and shells that don't conform to POSIX are less likely to find adoption because they will break user expectation.
- alkonaut 11y ago
- thisisdumbski 11y agoSeriously? I can't think of anything more pointless.
- shocks 11y agoTrying to improve our command line interfaces is not pointless.
- zenlot 11y agoAfter opening the link I expected to see an article from 90s, unfortunately it's from 2016... I can't believe that people still going into such debates.
- Ao7bei3s 11y agoNot all of us were around (as admins) in the 90s. If it was bad then, and it still (after 20 years) hasn't improved, then what do you expect?
- nunobrito 11y agoThe original article is about thinking on the end-user when designing new command line tools. Yet the replies seem to focus on why the current "ls" works so well. Ironically, very few can ever find a file on a subfolder without first googling for the syntax.. :-/
- IshKebab 11y agoThe complexity of the `find` command is the least of Unix's problems. How about defending these? 1. Unnecessary and confusing directory structure. `/etc`? Why not `/config`? `/usr` instead of `/system`, `/var` instead of ... well who knows. The maximum directory name length is no longer 3 characters. 2. Programs are mushed together and scattered through the filesystem rather than stored in separate locations. This basically means applications are install-only. Yeah, package managers try to keep track of everything, but that is just hacking around the problem, and most developers don't want to spend hours creating 5 different distro packages. 3. Not strictly Unix, but the mess of glibc with respect to ABI compatibility, static linking, etc. is ridiculous. Musl fixes most of this fortunately. 4. Emphasis on text-based configuration files. This is often ok, but it does make it hard to integrate with GUI tools, hence the lack of them. 5. Emphasis on shell scripts. Fortunately this is starting to change, but doing everything with shell scripts is terribly bug-prone and fragile. 6. X11. 'nuff said about that. When is Wayland going to be ready again? 7. General bugginess. I know stuff works 90% of the time, but that 10% is infuriating. Windows is a lot more reliable than Linux at having things "just work" these days.
- Jedd 11y ago> How about defending these? > 1. Unnecessary and confusing directory structure. `/etc`? Why not `/config`? > `/usr` instead of `/system`, `/var` instead of ... well who knows. The maximum > directory name length is no longer 3 characters. I know yrro already explained the ludicrously inconsistent nature of the OS you're apparently defending, but I'll add in: Why do I need to edit c:\Windows\System32\Drivers\etc\hosts (in what way is hosts related to bit-length or a driver?) Why .htm rather than .html? Why programiwanttorun.exe rather than programiwanttorun /system is as overloaded a word as any in IT. /config doesn't accurately reflect what /etc is about (but in any case, the latter is not a great barrier to entry) If you're complaining about limits on directory entries .. you're skating around on very thin ice if you're on the NTFS lake (compared to any of xfs, btrfs, reiserfs, ext2/3/4fs, etc) > 2. Programs are mushed together and scattered through the filesystem rather > than stored in separate locations. This basically means applications are > install-only. Yeah, package managers try to keep track of everything, but > that is just hacking around the problem, and most developers don't want to > spend hours creating 5 different distro packages. 14,000 registry entries for one suite of software ... how is that not 'mushed together and scattered'. Applications are not install-only. Because package managers (or, rather, distributions) managed to solve this problem elegantly more than a decade ago, I don't know how you can credibly make this claim. Is 'mushed together and scattered' a contradiction? Building packages for a variety of distros is a solved problem (again, it has been for a decade or more). > 3. Not strictly Unix, but the mess of glibc with respect to ABI compatibility, > static linking, etc. is ridiculous. Musl fixes most of this fortunately. It's hard to not sarcastically comment with the observation that the phrase DLL Hell did not originate within the nix world. More pragmatically, I rarely (in twenty years) have had glibc issues. I think perhaps 3 times. All easily solved. > 4. Emphasis on text-based configuration files. This is often ok, but it does > make it hard to integrate with GUI tools, hence the lack of them. The biggest complain with Win95 was the move away from .ini files (text-based). GUI tools do not intrinsically have an issue dealing with text-based configuration files. I posit the problem you're describing is the fact that text-based configuration files often contain useful human-readable components (which non-text-file config systems, such as 'the registry' lack) which is slightly harder to maintain using automated tools. But only slightly. As noted elsewhere, these are typically only a library call away. > 5. Emphasis on shell scripts. Fortunately this is starting to change, but > doing everything with shell scripts is terribly bug-prone and fragile. Doing anything badly is fragile. Shell scripts aren't intrinsically bad - as evinced by the success of shell scripts. I don't know many people who have significant experience with apt|rpm && sccm (for example) ... but I know a couple, and the fragility of shell scripts leads to fewer expletives than the alternative. > 6. X11. 'nuff said about that. When is Wayland going to be ready again? Are you suggesting that a system that completely disavows any network-awareness is preferable to one, designed >20 years ago, that does it fairly well? What problems have you had with X11 that aren't dwarfed by citrix / rdp / single-user consoles / etc? > 7. General bugginess. I know stuff works 90% of the time, but that 10% is > infuriating. Windows is a lot more reliable than Linux at having things > "just work" these days. Sounds like hyperbole. If things in the GNU/Linux world broke 10% of the time there'd be a lot fewer people using it - and if Microsoft Windows was more reliable than GNU/Linux, there'd be a lot more people moving towards it rather than away from it.
- joosters 11y agoI can never remember find's strange command line arguments, so I end up writing the easy replacement: find . |grep \\.txt The backslashes are not very intuitive, but if you miss them out entirely, you'll still likely get good enough results.
- BozeWolf 11y agoHaha! Yes! +1 for this. I do exactly the same thing. Or even just grep txt. The find command just is sometthing i cant get into my muscle memory (despite using linux for more the 15 years)
- rat87 11y agofor files on disk (not external disk) older then a day you can run `locate` or `locate --regex` Its faster since it uses a path database(If you have root you can run sudo updatedb to update it beforehand)
- someoneretarded 11y ago"Since we only use apt-get for installing stuff, why not? apt-get something instead of apt-get install something" wat? How dumb do people get?
- nunobrito 11y agoIf you read the blog carefully, you notice that the topic is about usability for upcoming command line tools. An hypothetical apt something follows the pattern found on curl, ping, unzip, ... Correcting user input when badly typed is something git already serves as example. So, labeling as dumb one of the parties at a discussion about intuitive command line switches as if they are immutable should be done with more substance. btw, when reading your reply this was the first thing coming to my mind: http://dilbert.com/strip/2007-11-16 http://dilbert.com/strip/2007-11-16 Have fun. :-)
- gtf21 11y agoPeople are still having windoze vs. unix fights? In this day and age?
- AsyncAwait 11y ago@7 I see this point repeated often without further clarification, what exactly is more buggy? I can tell you from personal experience that with a reasonably modern Linux distro, my laptop works out of the box without any problems and I've not experienced any significant system-level bugs in a long time. Meanwhile in Windows, my sound doesn't work at all when I wake up the laptop from sleep, Windows update tries to override the GPU driver with an older version from Windows update and every time I have > 10 Chrome tabs open, the whole system locks up regularly. Not to mention that the Windows registry is still a complete mess and trying to COMPLETELY remove a piece of software is an impossible task. I am not saying Linux is perfect and yes, Windows works better in the games department, but I am not sure I'll call Windows less buggy.
- FDominicus 11y ago1) could be a running gag. If you know it you know it, if you don't why not learn it? 2) mushed together /bin, /sbin/, /usr/bin, /usr/sbin/ usr local Well yes that may be hard to get if you exectubables are scatterd around as in windows in every other directoy. what a "big" difference 3) Yes DLl-Hell never ever has happened to Windows users - never 4) Oh yes it's better to have on registry and nobody knows which is for what. And if the registry is broken the whole system does not even run any more - yes that sounds as if that would be much better.. And no there is no graphical frontend for whatever in webmin. 5) Shell script are programs, and you can use them for scripting. what problem do you have with that? 6) So AFAIKT it runs here without troubles and update/upgrades are just an apt-get upgrade away. 7) Teh IT backbones are servers and most servers run under Linux. That should give you a hint. You arguments are none. They are just your opinion which is not backed by any knowledge. So welcome in the land of good-doers. Reliability is a word that Windows users have just learned the last few Windows incarnations. Long running servers are usual with Unices that's hardly the case for any Windows. And for Windows nearly all malware works. But hey who needs reliability if it's all that nice and colourful
- AndyMcConachie 11y agoThe equivalent of "dir *.txt /s" in UNIX is "ls -R|grep txt$".
- nunobrito 11y agoI find that syntax "good enough" for my own usage. YMMV when considering it outputting not just files with txt as extension, but also somewhere on its name. Someone else mentioned a workaround by adding the escaped dot in order to be fully equivalent to the dir syntax.
- skocznymroczny 11y agoIs Bash really better at wildcard expansion than cmd? I mean, sometimes you don't want to do wildcard expansion in the shell. copy .txt .bak would be much harder to write in Bash I suppose.
- dllthomas 11y agoFor the record, I would probably write this: for i in *.txt; do cp "$i" "${i%txt}.bak" done
- OJFord 11y ago> This is not available in the version of bash that comes > with OS X Almost nobody that doesn't comment "what's Terminal?" on an article/etc. should be using "the version of bash that comes with OS X".