4

Why do most *NIX commands my (experience is Linux mostly and rare encounter with FreeBDS) have such "insane" (unintuitive) default, behaviours, i.e. VERY different from what the "equivalent" GUI action would do.

The most obvious example is the file copy command, cp, that by default on Linux does (1) not copy directories recursively (obviously counterintuitive for anyone coming to the shell from previously using a GUI where a copy/paste copies a directory and everythind in it) and (2) follow simlinks (!!) instead of just copying them the way they are (again, as any GUI user would expect). So the "sane" version of cp that I imagine should be default is something like: cp -r.

(And again, this is not a "biased" perspective unique to someone who only used a GUI before. The DOS command copy for example does what you would expect, like an equivalent of cp -r or cp -ra...)

Another obvious example is the rm when rm -ri is what any non-shell-geek would expect to be the default.

And it goes on with 90% of all *NIX commands where to get what you would intuitively expect to be the default is something you achieve by adding a few more options. And is not as if what an advanced user expects to be the default is not what a novice user does, for things like cp and rm it's obvious that 99% of the time cp -r and rm -r is what you need. And is not as if things just needed to stay this way for backwards compatibility, as you can just create a new shell and keep #/usr/bin/oldshell or something for the old one.

So again, the question would be why are the default *NIX shell commands options/switches so far off for what you'd intuitively expect? Where can I find the historical arguments for how things are (even for anecdotical purpose) and what reason other then the obnoxious backwards-compatibility are for the current state of things?


Found this on unix.stackexchange which actually answers A LOT of my questions...

NeuronQ
  • 153
  • 6
  • Welcome to Superuser, please read what the [FAQ](http://superuser.com/faq#dontask) says about "chatty open-ended questions" – RedGrittyBrick Oct 13 '12 at 10:04
  • With cp, I suspect the command predated symlinks. There's a good chance that most of the people who would know why things were done a certain way are very old, or dead. A good chunk of commands may even pre-date unix – Journeyman Geek Oct 13 '12 at 10:13
  • "intuitive" is subjective. I'd be flabbergasted if `cp` was recursive by default and would say to myself "why on earth did someone design it this way". – Mat Oct 13 '12 at 10:16
  • @JourneymanGeek ...to understand what you mean it took me some time to realize that linux simlinks are more like hardlinks to applications, as opposed to windows shortcut files (never thought of it this way) ...but again, is history alone the reason for preserving unintuitive defaults? – NeuronQ Oct 13 '12 at 10:19
  • Absolutely. This means the commands used in the 70s *will work now*, in a predictable way. And simlinks are closer to 'file system pointers' than a windows shortcut. Symlinks are MUCH more powerful. – Journeyman Geek Oct 13 '12 at 10:21
  • @Mat ...WHY? In any graphical environment when you copy something you actually expect to be copying it (including its contents). Why are your expectations different in the shell. Even in the real world, when you xerox a piece of paper you expect to have an actual copy of it, not jut the title and subtitle at the top of the page... – NeuronQ Oct 13 '12 at 10:21
  • 2
    @NeuronQ: But, maybe graphical environments are doing it wrong ;p – Journeyman Geek Oct 13 '12 at 10:22
  • 1
    @NeuronQ: But to copy a book in the real world, you have to copy each page, not just lay it closed on the copier :) – choroba Oct 13 '12 at 10:23
  • @choroba OK, paper/book to folder analogy proves nothing, my bad, you're right. but the main point still stands – NeuronQ Oct 13 '12 at 10:25
  • @JourneymanGeek GUIs somehow model things by similitude with real world objects or real world interactions... and this has always worked well for creting intuitive interaces (take good old email messaging)... the shell seems to intentionally try to be as different as possible from any frequently used physical world concept or interaction... – NeuronQ Oct 13 '12 at 10:27
  • What is your main point? *Your* expectations are yours, from the way you learned stuff. Apparently, I didn't learn stuff the way you did and have different ones. Your "intuitive" is my "wtf". – Mat Oct 13 '12 at 10:28
  • And this is precisely why this is subjective, and is likely to be closed ;p – Journeyman Geek Oct 13 '12 at 10:39
  • @Mat As a GUI/UX designer I know that 99% of people have a common set of intuitions based on real world physical interactions. Smart people like you, have no problem thinking in terms of abstract concepts, but 90% of USERS don't have "abstract intuition" that ca freely swing in any direction, they have intuitions based on a common set of concepts and that's why all GUIs from Xerox's to today's desktops use a common set of "intuitive" concepts... You could just as well argue to drop all real-world analogies when designing GUIs and instead get inspiration from mathematical set theory :) – NeuronQ Oct 13 '12 at 10:39
  • 1
    @NeuronQ: it has nothing to do with "smarts". You're assuming that GUI are somehow "the way things should be" and that the design principles behind them should pretty much rule the world. That's not the case. There's no reason why CLI tools should be modeled with the same design principles as GUI tools (or the other way around). Different use-cases and different target audiences. – Mat Oct 13 '12 at 10:43
  • The general idea, and we "shell geeks" like it very much the way it is, because: things are well documented and behave the same way across different environments (computers). If you drag and drop something in one app, it will do as it pleases. No one ever reads how a GUI behaves. And the user manuals are crap. ...In another app (mac os - windows -gnome-kde ) if you drag and drop the results will vary (details). Whereas cp will ALWAYS do the same reliable thing it has done for 40+ years. cp -r will also do as you expect. IF you know what to expect from it - and you do if you read the man page. – Ярослав Рахматуллин Oct 13 '12 at 10:53
  • 1st, Becasue Unix wants to standardize only one -r for "recursive" have to memorize to used for grep,ls(R)/rm/cp, etc. 2nd, cp -nr(no_recursive) or cp -s(single) is more insane. 3rd, rm -r is more dangerous than rm, this is a safeguard. 4nd, recursive equivalent to loop concept in programming which require explicitly stated. – 林果皞 Dec 30 '15 at 12:11

1 Answers1

2

The commands do exactly as expected of them. You may find out what is reasonable to expect of a command by looking at the manual page for that command.

E.G.

man cp: -i, --interactive prompt before overwrite (overrides a previous -n option)

If you find yourself thinking that some options are good to have all the time, there are various vays of persisting your choices. You may for example type in:

alias rm="rm -i"
alias cp="cp -r"

But that will only last until you log out. To make such options permanent you can put these aliases in a file that is read by yor shell every time you log in. If you run bash, you can put your start-up commands in ~/.bashrc. Generally, ~/.profile is also a good place to put aliases.


The current state of things, when shells and command line utilities are concerned, is far from obnoxious. The initial shock of using the terminal instead of a graphical browser, may leave you confused and maybe somewhat enraged, but only after a couple of years You'll get very used to it and will laugh back at the time when you used to think that a GUI browser was "the current state of things".

For the sake of good will, and to welcome you to the world of command line interface I'll give you a couple of my favorite aliases. And I'll give you that cp -i and rm -i are byt far better to have as the default commands, because it's very easy to make a mistake and remove a lot of files unintentionally. I don't agree on the recursive option though.

# basic file manipulation, etc
alias cd....='cd ../..'
alias  cd...='cd ../..'
alias   cd..='cd ..'
alias    cd.='cd .'
alias    cd~='cd ~'
alias   ....='cd ../..'
alias    ...='cd ../..'
alias     ..='cd ..'
alias      ~='cd ~'

alias ls='ls --color=auto'
alias l='ls -CF'
alias l1='ls -1'
alias ll='ls -l'
alias lla='ls -la'
alias la='ls -a'


alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias mc='mv -i'

alias md="mkdir"
alias rd="rmdir"

alias less="less -i"
alias bc="bc -q"
alias KA="killall"

alias swipe='screen -wipe'
alias sdr='screen -dR $1'

# and some functions: 

spelling ()  {      echo $@ | LC_ALL=en_US aspell -a; }

google-search () {
    BROWSER="firefox '%s' &"
    args="${@}";
    args=`echo $args | sed 's/ /%20/g'`;
    url="https://www.google.no/search?hl=en&um=1&sa=1&q=";
    printf "$BROWSER\n" "$url$args" | sh
}