歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux管理 >> Linux維護 >> Linux初學者需了解的Bash命令操作技巧分享

Linux初學者需了解的Bash命令操作技巧分享

日期:2017/3/2 10:36:39   编辑:Linux維護

Bash是Bourne-Again SHell的縮寫,是許多Linux平台內定的shell,其實Bash命令有許多操作技巧,很多初學者可能還不知道,掌握這些技巧能夠更快的完成工作,一起來學習下吧。

tab鍵補全用法

當我們敲擊一下tab補全命令或文件名

當我們敲擊兩下tab 列出相關的所有可選項

cd - 相當於電視的回看

有時候我們進入一個非常長的目錄,後來又進入另一個目錄,可能我們還行回到原來那個長,如果事先知道,我們可能輸入pwd ,以便一會兒粘貼,有時候忘了輸入pwd我們可能無奈還得輸入一次長長的路徑,我們可以輸入一下cd -試試,直接回到上次進入的目錄,就像是看電視時候的回看按鈕。是不是很好用?

查看以下例子

[root@localhost /]# cd /tmp

[root@localhost tmp]# pwd

/tmp

[root@localhost tmp]# cd /

[root@localhost /]# pwd

/

[root@localhost /]# cd -

/tmp

[root@localhost tmp]# pwd

/tmp

Esc+.

用法舉例

首先touch一個文件,然後編輯這個文件

touch abcdefghijk

敲入vi ,然後Esc+. 發現是不是abcdefghijk已經出現在vi後面\

轉義字符用法

系統中一些命令都是別名的功能,比如我們使用的rm、mv等,實際上是 rm -i和mv -i 。

查看系統別名可以使用alias命令,例如以下系統默認的別名。

[root@localhost testdir]# alias

alias cp=‘cp -i’

alias egrep=‘egrep --color=auto’

alias fgrep=‘fgrep --color=auto’

alias grep=‘grep --color=auto’

alias l.=‘ls -d .* --color=auto’

alias ll=‘ls -l --color=auto’

alias ls=‘ls --color=auto’

alias mv=‘mv -i’

alias rm=‘rm -i’

alias which=‘alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde’

有時候我們刪一個文件時候,會出現以下提示, 需要我們一個個確認,原因就是rm默認就是rm -i起了作用。

[root@localhost testdir]# cd dir1

[root@localhost dir1]# ls

file1 file2 file3 file4

[root@localhost dir1]# rm file1 file2 file3 file4rm: remove regular empty file ?.ile1?。 y

rm: remove regular empty file ?.ile2?。 y

rm: remove regular empty file ?.ile3?。 y

rm: remove regular empty file ?.ile4?。 y

我們可以使用轉移字符使別名失效,使用如下,刪除就不會再有提示確認了。

[root@localhost testdir]# cd dir1

[root@localhost dir1]# ls

file1 file2 file3 file4

[root@localhost dir1]# \rm file1 file2 file3 file4

上面就是bash命令的操作技巧的介紹了,想要學的精,光掌握命令是不夠的,還要靈活應用一些操作技巧,這樣才能事半功倍,你學會了嗎?

Copyright © Linux教程網 All Rights Reserved