Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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...

share|improve this question

closed as not constructive by RedGrittyBrick, Journeyman Geek, Nifle, slhck Oct 13 '12 at 10:52

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Welcome to Superuser, please read what the FAQ 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
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
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

1 Answer 1

up vote 3 down vote accepted

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
}
share|improve this answer
    
Thanks! But what is alias cd.='cd .' supposed to do? Isn't . the current dir? –  NeuronQ Oct 13 '12 at 10:51
    
I used to forget the space or misspell the command. I can't really remember why I thought that alias was useful, I've had it for some years. I don't use cd. anymore. I just gave you a couple of examples... –  Ярослав Рахматуллин Oct 13 '12 at 10:56
1  
When your current directory has been deleted and recreated, cd . allows you to switch from the old stale directory to the new one. –  BatchyX Oct 13 '12 at 13:04
    
Yeah, ok, but how often does that happen? I think I mean for cd. to be cd .. –  Ярослав Рахматуллин Oct 13 '12 at 13:06
1  
@BojanMarkovic, ~ is the default location for cd, so you never have to type cd ~ because just cd will take you there. –  OmnipotentEntity Nov 15 '13 at 16:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.