天天看點

linux運維基礎1

一、虛拟機控制

1、開啟虛拟機:

[kiosk@foundation0 Desktop]$ rht-vmctl start desktop       ###開啟desktop虛拟機

2、顯示虛拟機:

[kiosk@foundation0 Desktop]$ rht-vmctl view  desktop       ###顯示desktop

3、關閉虛拟機:

[kiosk@foundation0 Desktop]$ rht-vmctl poweroff desktop     ###關閉dekstop

Powering off desktop..

4、特殊問題:

Error: unable to view desktop - not currently running.   ###虛拟機沒開啟無法顯示

[kiosk@foundation0 Desktop]$ rht-vmctl reset desktop     ###當虛拟機出現故障,reset表示重置

Are you sure you want to reset desktop? (y/n) y          ###詢問是否重置y表示yes

Resetting desktop.                                       ##正在重置

注意:當你不小心删除重要檔案導緻系統崩潰好或者出現故障時,reset重置。建議初學者用虛拟機進行練習,這樣練習時要是出現什麼問題不會威脅到你本身的電腦,也能随時重置虛拟機,友善你們大膽練習。

二、語言調整

在使用虛拟機時調整輸入語言:

Applications    ----->system tools---->settings ----->Region & language --->language 

  三、第一單元 

1、行提示符

我們剛打開一個shell時出現的界面:

linux運維基礎1

root                            ##打開shell的使用者  root為管理者

@                               ##分隔符

localhost                       ##主機名稱

Desktop                         ##工作目錄名稱

#                               ##身份提示符,#表示超級使用者,$表示普通使用者

注意:指令要在行提示符之後輸入才能執行

2、切換使用者

指令:su - username

進階使用者切換到低級使用者不需要密碼,低級使用者切換到進階或者平級使用者的切換需要密碼

linux運維基礎1

第一步是從root切換到student,不需要輸入密碼;第二步是從student切換到root,提示需要輸入密碼;第三步是從root使用者退出,回到上一次登陸身份student;第四步是從student使用者退出,回到上一次登陸身份root. 

su - :切換到上一次登入的使用者身份。

多次切換使用者後記得用exit指令登出!

3、虛拟控制台

指令:

        Ctrl+Alt+F(1|7)            進入圖形

        Ctrl+Alt+F(2~6)            進入虛拟控制台

Red hat Enterprise Linux Server 7.0 (Maipo)            ##系統版本

Kernel 3.10.0-123.el7.x86_64 on an x86_64              ##核心版本,系統位數

desktop0 login:root              ##登陸使用者名稱輸入

Password:                        ##密碼輸入無回顯

4、指令的執行

(1)指令必須在行提示符之後輸入

(2)指令格式

[kiosk@foundation0 Desktop]$ 指令 參數 目标

linux運維基礎1

(3)ctrl +c        ##撤銷命名的執行

    [root@localhost Desktop]# aaaaa^C

(4)指令參數

-參數        ##單詞縮寫    -h 

--參數       ##單詞的全拼    --help

5、指令的幫助

(1)檢視指令的功能:  whatis 指令

[root@localhost Desktop]# whatis ls

ls                   (1)  - list directory contents

ls                   (1p)  - list directory contents

(2)檢視指令的幫助:  指令 --help

linux運維基礎1

[]              ##選擇加入的内容,可加可不加

...             ##加入的内容個數任意

<>              ##内容在指令執行過程當中必須要加

    man 指令

linux運維基礎1

 q:退出幫助界面

man和--help都是檢視指令幫助

.. --help查找到的比較簡單實用;man查找到的比較全面;

.. --help隻能用滑鼠翻頁;man可以用上下鍵或者空格鍵來翻頁;

6、系統的使用基礎方法

1)系統登陸

圖形登陸方式

文本登陸方式

gnome-session-quit --force    ###登出使用者 --force強制登出,不詢問

2)工作界面轉換

ctrl+alt+上|下

3)開始bash

1.Applications>Utilities>Terminal

2.滑鼠右鍵----->open in terminal

3.gnome-terminal

4.ctrl+shift+n        ##在新視窗中打開shell

  ctrl+shift+t        ##同一個視窗中打開新的tab

5.退出:exit | ctrl+d

4)系統關機,重新開機

重新開機

reboot | init 6 |shutdown -r now

關機

poweroff | init 0 | shutdown -h now

5)鎖屏

ctrl + alt +L        ##在rhel7.0

win鍵 + L            ##在rhel7.2

7、簡單的系統指令

1) date  : 顯示目前時間

  date [OPTION]...[+FORMAT]...: 顯示

              FORMAT:格式符号

                     %D

                     %F

                     %T

  date[MMDDhhmm[[cc]YY][.ss]];設定

              MM:月份

              DD:幾号

              hh:小時

              mm:分鐘

              YY:兩位年份

              CCYY:四位年份

              .ss:秒鐘

XXXXXXX

[root@localhost Desktop]# date

Mon Sep 25 03:24:42 PDT 2017

不加參數表示顯示目前系統時間。

[root@localhost Desktop]# date 11181115

Sat Nov 18 11:15:00 PST 2017

[root@localhost Desktop]# date 111811152016.55

Fri Nov 18 11:15:55 PST 2016

watch -n 1 date     ###讓date指令每秒執行一次,ctrl +c 退出監控模式

-d +xday /-xday    ##檢視x天前或者後的時間

Fri Nov 18 11:19:11 PST 2016

[root@localhost Desktop]# date -d +5days          檢視五天後的時間

Wed Nov 23 11:19:13 PST 2016

+%....        ##設定date的輸出格式

2)passwd

1.passwd 修改使用者密碼

[root@foundation0 ~]# passwd

Changing password for user root               ##改變超級使用者密碼

New password:                                 ##輸入密碼

BAD PASSWORD: The password is shorter than 8 characters

Retype new password:                          ##确認密碼

passwd: all authentication tokens updated successfully.

[kiosk@foundation0 Desktop]$ passwd

Changing password for user kiosk.        ##改變普通使用者密碼

Changing password for kiosk.

(current) UNIX password:                 ##輸入目前密碼

New password:

BAD PASSWORD: The password is the same as the old one##和原始密碼不能相似

New password: 

BAD PASSWORD: The password fails the dictionary check - it is too simplistic/systematic ##密碼必須是無序數字+字母

BAD PASSWORD: The password is shorter than 8 characters##密碼必須>8位

passwd參數使用者名稱

-Sstudent            ##使用者密碼資訊

--status student。。。。。。

-l student            ##鎖定帳号

-u student            ##解鎖

-n 1student            ##設定密碼最短有效期

-x 30student        ##設定密碼最長有效期

-w 3student        ##警告期

-i 2student        ##設定使用者非活躍天數

-dstudent        ##清除使用者密碼

監控passwd密碼資訊

watch -n 1 passwd -S student

linux運維基礎1

3)file

file 檔案名字       ##檢視檔案類型

linux運維基礎1

檔案的類型是由内容決定的,不是由字尾決定

linux運維基礎1

4)檔案的檢視

cat filename           ##檢視檔案的全部内容    靠後顯示

  -b  顯示行數(不算空行)

  -n  顯示行數(算空行)

注意:cat檢視檔案沒反應,說明該檔案為空;

less file          ##分頁浏覽,按“q”退出 從第一行顯示檔案内容 可以搜尋關鍵字

head filename      ##顯示一個檔案的前幾行  預設顯示前十行

head -n 5 filename  ##前五行

[root@localhost Desktop]# head -5 westos

wodimama

s1

2

3

4

tail filename          ##顯示檔案後幾行        預設顯示後十行

tail -n 5 filename     ##顯示一個檔案的後5行

[root@localhost Desktop]# tail -5 westos

26

27

28

29

30

5)wc:統計檔案容量資訊    預設顯示:行數 單詞數 位元組  

wc -l     行數

   -w     單詞數

   -c     位元組數

   -m     字元數

[root@localhost Desktop]# cat file

hello world!

nice to meet you!

[root@localhost Desktop]# wc westos

33 31 92 westos

[root@localhost Desktop]# wc file

 2  6 31 file

[root@localhost Desktop]# wc -l file

2 file

[root@localhost Desktop]# wc -w file

6 file

[root@localhost Desktop]# wc -c file

31 file

[root@localhost Desktop]# wc -m file

另外:一個中文占三個字元,a是一個字元資料,記憶體配置設定給字元資料預設是兩個位元組(B)。

8、tab鍵

在系統中table鍵可以自動補齊存在的指令,檔案名稱和某些指令的參數

a+TAB x2  顯示系統中所有a開有的指令

[root@localhost Desktop]# cat westos

westos       westos.jpg   westos.mp3   westos.png   westos.txt~  

westos~      westos.jpg~  westos.mp3~  westos.txt  

hostory -c              ##清除目前環境當中的曆史指令

!數字                  ##執行第多少行指令

!字母                  ##執行最近一條以這個字母開頭的指令

ctrl +R +關鍵字         ##執行最近一條含有這個關鍵字的指令

上下鍵                  ##逐行調用指令

[root@localhost Desktop]# history    顯示目前環境當中的曆史指令

    1  history

    2  wc -l file

    3  wc -w file

    4  wc -m file

    5  history

[root@localhost Desktop]# !2      執行第2條指令

wc -l file

9、linux中的快捷鍵

左右                    ##一個字元一個字元移動

ctrl +左右              ##一個字一個字移動

ctrl    + a             ##光标移動到行首

        + e             ##光标移動到行尾

        + u             ##光标所在位置删除到行首

        + k             ##光标所在位置删除到行尾

        + r+關鍵字        ##調出最近一條含有關鍵字的指令

        + c             ##撤銷以輸入的指令

        + d             ##關閉目前環境

        + L            ##清空螢幕

        + shift + c        ##複制

        + shift + v        ##粘貼

        + shift + t     ##在現有shell中重新打開一個table        

        + shift + n    ##在shell中打開一個新的shell

        + shift + pageup|pagedown ##切換table

        + alt + l          ## 鎖屏

        + alt +上|下        ##切換工作界面

繼續閱讀