linux:命令列操作及常用命令使用,linux常用命令

來源:互聯網
上載者:User

linux:命令列操作及常用命令使用,linux常用命令
  1.1命令列操作
  1.1.1 Shell簡介
  在學習shell之前我們先來瞭解什麼是Shell,Shell能完成的功能是什麼,常見的shell的類型是什嗎?為什麼用使用Shell?
  Shell是使用者和Linux作業系統之間的介面,在百科中shell俗稱殼(用來區別於核),是指“提供使用者使用介面”的命令解析器。類比有DOS中的command和windows常見的cmd。用來接收使用者的命令,然後調用相應的應用程式。
  這裡我們說的是Linux底下的Shell,Linux有很多種的Shell,其中常見的就是我們經常使用的bash。
  在企業中部署的伺服器亦或是linux大白,大牛使用的Linux系統中,基本使用的都是迷你安裝,完全拋棄掉圖形化,需要什麼工具就yum安裝。所以Shell作為作業系統的外核為使用者提供使用作業系統的介面,它可以說是命令語言解譯器,擁有自己內建的shell命令集,我們在使用tab鍵的時候,可以彈出補全命令的提示。Shell使得使用者在提示符下輸入的命令都由shell先解釋然後傳給Linux核心。
 
  shell是UNIX系統用使用者與作業系統互動的最基本工具,實際上shell除了有命令解釋執行的功能外,還具有其他的功能: 1)系統內容的設定 2)輸入輸出的重新導向 3)shell程式語言的設計等
  不同的Shell在應用中各有所長,以下是幾種常見類型的shell。
  1)Bourne Shell是UNIX最初使用的shell,並且在每個Unix上都可以使用,Bourne SHell在編程方面相當優秀,但是在處理與使用者的互動介面上做的不如其他的Shell,現如今我們常說的bash(Bourne Agair Shell),它就是在Bourne Shell上的基礎上增加了許多的特性。
  2)C shell 是一種適於編程的 shell, 它的文法與 C 語言很相似,Linux 為喜歡使用 C shell 的人提供了 Tcsh。Tcsh 是 C shell 的一個擴充版本,Tcsh 包括命令列編輯可程式化單詞補全、拼字校正、曆史命令替換、作業控制和類似 C 語言的文法,它不僅和 Bash shell 是提示符相容,而且還提供比 Bash shell 更多的提示符參數
3)Korn shell 集合了 C shell 和 Bourne shell 的優點並且和 Bourne shell 完全相容 Linux 系統提供pdkshksh 的擴充。它支援任務控制,可以在命令列上掛起、後台執行、喚醒或終止程式。

3)Korn shell 集合了 C shell 和 Bourne shell 的優點並且和 Bourne shell 完全相容 Linux 系統提供pdkshksh 的擴充。它支援任務控制,可以在命令列上掛起、後台執行、喚醒或終止程式。

Redhat Linux系統預設Shell是Bash shell,超級使用者用#做提示符(root相當於windows的administrator使用者,許可權很大,在使用上用很大的風險。企業和學習中最好使用普通使用者)。在Linux中,普通使用者用$做為提示符。我們可以在root使用者和普通使用者上鍵入命令完成我們所要達到的任務和學習。

1.1.2Redhat發行版

常見的linux發行版本按照RPM方法安裝軟體的系統,包括Red Hat,Fedora,SuSE,Centos系統;另外一類是使用Debian的dpkg方式安裝軟體的,包括Ubuntu、Debain,B2D等等,因為國內使用的都是類Redhat的環境,我上學的時候使用的也是Centos系統,所以以下的學習環境都是在Centos下完成。

版本為Centos7.2

[root@kvm ~]# uname -aLinux kvm 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

下面我們一起來操作shell是怎麼進行的,我們在shell輸入以下命令:ls -al

[root@kvm ~]# ls -altotal 88dr-xr-x---. 22 root root  4096 Oct 31 19:22 .dr-xr-xr-x. 17 root root  4096 Oct 30 06:07 ..-rw-------.  1 root root  1619 Oct 22 01:57 anaconda-ks.cfg................................................drwxr-xr-x.  2 root root     6 Oct 23 20:48 下載drwxr-xr-x.  2 root root     6 Oct 23 20:48 公用drwxr-xr-x.  2 root root     6 Oct 23 20:48 圖片drwxr-xr-x.  2 root root     6 Oct 23 20:48 文檔drwxr-xr-x.  3 root root    33 Oct 31 19:30 案頭drwxr-xr-x.  2 root root     6 Oct 23 20:48 模板drwxr-xr-x.  2 root root     6 Oct 23 20:48 視頻drwxr-xr-x.  2 root root     6 Oct 23 20:48 音樂
ls -al 該命令可以勒出目前的目錄下的所有檔案和子目錄。

我們在登入到linux時,系統會讀書/etc/passwd檔案來決定要使用哪個shell,例如我使用了root使用者顯示的就是

[root@kvm ~]# cat /etc/passwd  |grep rootroot:x:0:0:root:/root:/bin/bash
使用test使用者顯示的就是
test:x:1001:1001::/home/test:/bin/bash
使用者之間的切換使用的是命令 su
[test@kvm root]$ su      #單獨輸入su 會切換到root使用者Password:                #輸入root密碼[root@kvm ~]# su test    #切換到test使用者[test@kvm root]$         #成功切換到test使用者

我們可以使用上下箭頭上查看我們使用了哪些命令,如果命令較多,我們也可以用history來查看曆史命令。

[root@kvm ~]# history    1  vim /etc/locale.conf    2  reboot    3  ls    4  netstat -antp |grep 5901    5  systemctl status vncserver@:1.service    6  systemctl restart vncserver@:1.service    7  vim /etc/libvirt/qemu    8  vim /etc/libvirt/qemu.conf     9  systemctl restart vncserver@:1.service   10  systemctl restart firewalld.service   11  systemctl status firewalld.service   12  systemctl restart firewalld.service   13  systemctl restart vncserver@:1.service

如果只想顯示最後n行可以使用 history 可以使用history -n
[root@kvm ~]#  history 10

1.1.3Linux 是一個真正的多使用者作業系統 這表示它可以同時接受多個使用者登入Linux 還允許一個使用者進行多次登入。如同我使用的伺服器Dell R710,就有兩個使用者,我們可以使用putty或者Xshell工具遠程進入控制台系統。我們可以使用whoami來看看是誰控制了系統。

[root@kvm ~]# whoamiroot[root@kvm ~]# su test[test@kvm root]$ whoamitest
使用last查看當前登入和過去登入的使用者資訊
root     pts/3        :1               Mon Oct 23 13:29 - down   (00:01)    root     pts/2        192.168.0.2           Mon Oct 23 13:24 - down   (00:06)    root     pts/1        :0               Mon Oct 23 20:56 - down   (-7:-25)   root     pts/0        :0               Mon Oct 23 20:56 - down   (-7:-25)   root     :0          :0               Mon Oct 23 20:56 - 13:31  (-7:-25)      reboot   system boot  3.10.0-327.el7.x Mon Oct 23 20:55 - 13:31  (-7:-24)   root     pts/1        :0               Mon Oct 23 20:49 - crash  (00:06)    root     pts/0        :0               Mon Oct 23 20:48 - crash  (00:06)    root     :0          :0               Mon Oct 23 20:48 - 20:49  (00:01)     reboot   system boot  3.10.0-327.el7.x Mon Oct 23 20:47 - 13:31  (-7:-16)   reboot   system boot  3.10.0-327.el7.x Mon Oct 23 20:41 - 13:31  (-7:-10)       reboot   system boot  3.10.0-327.el7.x Mon Oct 23 20:25 - 20:32  (00:06)    reboot   system boot  3.10.0-327.el7.x Sun Oct 22 02:06 - 02:07  (00:01)    reboot   system boot  3.10.0-327.el7.x Sun Oct 22 02:01 - 02:07  (00:05)

常見的遠程方式一般有talent遠程登入(傳輸明文不安全)常使用的有ssh遠端連線和VNC串連。具體後面會講,我也是想到那寫到。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.