Linux基本指令(一)
[kiosk@foundation20 Desktop]$ rht-vmctl start desktop //開啟虛擬機
[kiosk@foundation20 Desktop]$ rht-vmctl view desktop //顯示虛擬機
[kiosk@foundation20 Desktop]$ rht-vmctl stop desktop //正常關閉虛擬機
Stopping desktop.^C[kiosk@foundation20 Desktop]$ //ctrl+c退出當前操作
[kiosk@foundation20 Desktop]$ rht-vmctl poweroff desktop
[kiosk@foundation20 Desktop]$ rht-vmctl reset desktop //重置虛擬機並開機
[kiosk@foundation20 Desktop]$ gedit //打開記事本
二、時間
cal //調出當月日歷 -h 可查看其參數
date MMDDhhmmCCYY.ss //設置時間
date -d +/-數字day //顯示不是今天的日期
date +Format //按照指定的格式顯示時間(不要忘記加號) --h 可查看其參數
三、密碼
watch -n 1 指令 //監控該指令 每1s更新一次
watch -n 1 passwd -S student
passwd //修改密碼
su - student //切換用戶 su空格-空格用戶名
passwd -l student //鎖定該用戶密碼
passwd -u student //解鎖該用戶密碼
passwd -n 1 student //每一天只允許修改一次密碼(最短有效期)
passwd -x 30 student //該密碼只能用30天 之後鎖定該密碼(最長有效期)
passwd -w 2 student //密碼期限剩余2天時提醒(警告期)
passwd -i 3 student //密碼到期後寬限還能再使用3天(非活躍天數)
passwd -S student //查看密碼信息
四、文件及目錄操作
cat Myfile //查看文件Myfile
less Myfile //分頁查看Myfile q 推出
head -n 5 Myfile //查看前5行
tail -n 5 Myfile //查看後5行
wc Myfile //查看文件Myfile信息 行數 單詞數 字節數 文件名
wc -l//行數 -w//單詞數 -c//字節數 -m//字符數
touch file //修改文件的時間戳 創建文件file
mkdir directory //創建目錄
mkdir -p directory //叠代創建目錄
rm file //刪除文件
rm -f file //強制刪除文件
rm -r directory //叠代一級一級刪除目錄
rm -rf directory //強制刪除目錄
rm -rf * //刪除當前目錄所有
五、常用查看指令
history //查看歷史操作
!127 //執行127行歷史操作
Ctrl+r 輸入關鍵字 //執行與關鍵字有關的最近的歷史操作
history -c //刪除所有歷史操作記錄
pwd //顯示當前路徑
stat file/directory //顯示文件/目錄信息
vim file //按編輯器的方式打開文件file i//編輯 esc :q!/wq//退出
cd - //返回上次的目錄
cd .. //返回上一層
cd ~ //返回home目錄
ls //顯示當前目錄下的文件及目錄
ls -a //顯示當前目錄下的所有文件及目錄(包括了. ..隱藏文件)
ls -l file/directory //詳細顯示文件/目錄
ls -d //列出目錄本身
ls -R directory //第歸顯示目錄中的內容
六、復制移動操作
mv file file1 direcotry //移動file file1到directory中
mv 存在文件 不存在文件 //重命名文件
mv westos/linux . //把westos中的linux移動到當前目錄 .代表當前目錄
cp file file1 file2 ... directory //把file file1 file2 復制到 directory中
cp file test //建立test文件模板為file
cp -r directory direcotry1 //復制目錄
七、正則表達式
* ###匹配0到任意字符
? ###匹配單個字符
[[:alpha:]] ###匹配單個字母
[[:lower:]] ###匹配單個小寫字母
[[:upper:]] ###匹配單個大寫字母
[[:digit:]] ###匹配單個數字
[[:alnum:]] ###匹配單個數字或字母
[[:punct:]] ###匹配單個符號
[[:space:]] ###匹配單個空格
{}表示不存在的或者存在的
{1..9} ###1-9
{a..f} ###a-f
{1,3,5} ###135
{a,c,e} ###a c e
{1..3}{a..c} ###1a 2a 3a 2a 2b 2c 3a 3b 3c
[]表示存在的
[a-C] ###aA bB cC
[a-c] ###aA或者bB或者c
[1-3] ###1或者2或者3
[145] ###1或者4或者5
[^abc]|[!abc] ###除了a並且除了b並且除了c
egg:
touch fiale fiAle fi2le fi_le "fi le"
rm -f fi[[:alpha:]]le //匹配字母
rm -f fi[[:upper:]]le //匹配大寫字母
rm -f fi[[:lower:]]le //匹配小寫字母
rm -f fi[[:alnum:]]le //匹配數字
rm -f fi[[:punct:]]le //匹配符號
rm -f fi[[:space:]]le //匹配空格
touch file{1..10}
touch file{a..z}
touch file{a,b,c}
rm -f file{1..10}
rm -f file[1..9] //[]最大到9且只能用於刪除不能用於創建
rm -f file\[1..9\] //刪除一個文件 file[1..9]
rm -f [!abc]
rm -f [^abc] //相當與!取非
Linux基本指令(一)