4.基本的命令

接著,我們來看一些基本的命令吧。有內建的及命令列程式二種

是不是內建命令,可以用 'type 命令' 看出來,如:

type echo 結果為 echo is a shell builtin,表示它為內建命令

type mkdir 結果為 mkdir is /bin/mkdir,表示它為命令列程式

bash shell 的內建命令

bash shell 的內建命令不必再去搜尋路徑中去尋找,直接就可執行,速度很快。

常見的有:

alias, bg, bind, break, builtin, case, cd, command, compgen,
complete, continue, declare, dirs, disown,  echo,  enable,  eval,  exec,  exit,
export,  fc, fg, for, getopts, hash, help, history, if, jobs, kill, let, local,
logout, popd, printf, pushd, pwd, read, readonly, return,  set,  shift,  shopt,
source,  suspend,  test,  times,  trap,  type, typeset, ulimit, umask, unalias,
unset, until, wait, while

以下介紹幾個簡單命令的用法

alias

用途:顯示及設定程式別名

用法:

  1. alias

    結果:顯示目前所有的己經設定的程式別名

    如下所示:

    alias ll='ls -l --color=tty'
    alias ls='ls --color=tty'
    alias vi='vim'
    alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

  2. alias new='old'

    結果:設定程式別名

    如下所示:

    alias cp='cp -f'
    
    把 cp 用 cp -f 重新定義,執行 cp 即等於執行 cp -f

  3. unalias 別名

    結果:取消程式別名

    如下所示:

    unalias cp
    
    把 cp 的別名設定取消