1. 程式人生 > >linux運維基礎1

linux運維基礎1

liunx

#################虛擬機控制##############

[[email protected] Desktop]$ rht-vmctl start desktop###開啟desktop虛擬機

Error: desktop not started (is already running)###報錯,desktop已經運行

[[email protected] Desktop]$ rht-vmctl view desktop###顯示desktop

[[email protected] Desktop]$ rht-vmctl poweroff desktop ###關閉dekstop

Powering off desktop..

[[email protected] Desktop]$ rht-vmctl start desktop ###開啟desktop

Starting desktop.

[[email protected] Desktop]$ rht-vmctl view desktop

[[email protected] Desktop]$ rht-vmctl poweroff desktop

Powering off desktop..

[[email protected] Desktop]$ rht-vmctl view desktop

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

[[email protected] Desktop]$ rht-vmctl reset desktop ###當虛擬機出現故障,reset表示重置

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

Resetting desktop.##正在重置

Powering off desktop..


###語言調整#####

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


######################

##### 第一單元 #####

######################


###1.行提示符######

[[email protected] Desktop]$

kiosk##打開shell的用戶

@##分隔符

foundation0##主機名稱

Desktop##工作目錄名稱

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


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


####2.切換用戶#######

[[email protected] Desktop]$ su - username

*)高級用戶切換到低級用戶不需要密碼,低級用戶切換到高級或者平級用戶的切換需要密碼

技術分享

多次切換用戶後記得用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.命令格式

[[email protected] Desktop]$ 命令 參數 目標

技術分享

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

4.命令參數

-參數##單詞縮寫

--參數##單詞的全拼



#######5.命令的幫助###

1.

whatis 命令##查看命令的功能

命令 --help##查看命令的幫助

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

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

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

技術分享



#####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


###簡單的系統命令

1) date : 顯示當前時間

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

FORMAT:格式符號

%D

%F

%T

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

MM:月份

DD:幾號

hh:小時

mm:分鐘

YY:兩位年份

CCYY:四位年份

.ss:秒鐘


[[email protected] Desktop]# date

Mon Sep 25 03:24:42 PDT 2017

eg:date 11181115 ###把系統時間設定為11月18日11:15 格式:月月天天小時分鐘

date 111811152016.55 ##2016表示年(可以不加).55 表示秒(可以不加)

[[email protected] Desktop]# date 11181115

Sat Nov 18 11:15:00 PST 2017

[[email protected] Desktop]# date 111811152016.55

Fri Nov 18 11:15:55 PST 2016

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

-d +xday /-xday##查看x天前或者後的時間

[[email protected] Desktop]# date

Fri Nov 18 11:19:11 PST 2016

[[email protected] Desktop]# date -d +5days

Wed Nov 23 11:19:13 PST 2016

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


2)passwd

1.passwd 修改用戶密碼

[[email protected] ~]# 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.



[[email protected] 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 ##密碼必須是無序數字+字母

New password:

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


passwd參數用戶名稱

-Sstudent##用戶密碼信息

--status student。。。。。。

-lstudent##鎖定帳號

-ustudent##解鎖

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

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

-w 3student##警告期

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

-dstudent##清除用戶密碼

監控passwd密碼信息

watch -n 1 passwd -S student

技術分享


3)file

file 文件名字##查看文件類型

技術分享


文件的類型是由內容決定的,不是由後綴決定

技術分享


4)文件的查看

cat filename ##查看文件的全部內容 靠後顯示

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

-n 顯示行數(算空行)

註意:cat查看文件沒反應,說明該文件為空;

less file ##分頁瀏覽,按“q”退出 從第一行顯示文件內容 可以搜索關鍵字

head filename ##顯示一個文件的前幾行 默認顯示前十行

head -n 5 filename ##前五行

[[email protected] Desktop]# head -5 westos

wodimama

s1

2

3

4

tail filename ##顯示文件後幾行 默認顯示後十行

tail -n 5 filename ##顯示一個文件的後5行

[[email protected] Desktop]# tail -5 westos

26

27

28

29

30


5)wc:統計文件容量信息 默認顯示:行數 單詞數 字節


wc-l行數

-w單詞數

-c字節數

-m字符數


[[email protected] Desktop]# cat file

hello world!

nice to meet you!

[[email protected] Desktop]# wc westos

33 31 92 westos

[[email protected] Desktop]# wc file

2 6 31 file

[[email protected] Desktop]# wc -l file

2 file

[[email protected] Desktop]# wc -w file

6 file

[[email protected] Desktop]# wc -c file

31 file

[[email protected] Desktop]# wc -m file

31 file


另外:一個中文占三個字符,a是一個字符數據,內存分配給字符數據默認是兩個字節(B)。



#####tab鍵######

在系統中table鍵可以自動補齊存在的命令,文件名稱和某些命令的參數


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

[[email protected] Desktop]# cat westos

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

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


hostory -c ##清除當前環境當中的歷史命令history##顯示歷史####history歷史調用######

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

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

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

上下鍵##逐行調用命令

[[email protected] Desktop]# history

1 history

2 wc -l file

3 wc -w file

4 wc -m file

5 history

[[email protected] Desktop]# !2

wc -l file

2 file



#####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 +上|下 ##切換工作界面

+ alt + f1|f7 ##進入圖形界面

+ alt + f2-f6 ##進入虛擬控制臺


linux運維基礎1