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

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
}