Linux部分命令及使用

Linux部分命令解釋及使用


ASCII 信息交換碼 
GB2312
big5
UTF-8 字符集
亂碼問題 生產環境中最常見故障  字符集格式設置不一致
查看系統版本  cat /etc/redhat-release 
$() “  
echo “This system’s name is $(hostname)”
This system’s name is cent7.magedu.com
echo “This system’s name is `hostname`”
This system’s name is cent7.magedu.com
[root@cent7 ~]# name=hostname
[root@cent7 ~]# echo “This system’s name is `$name`”
This system’s name is cent7.magedu.com
括號擴展 {}
[root@cent7 ~]# echo {1..10}
1 2 3 4 5 6 7 8 9 10
[root@cent7 ~]# echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z
[root@cent7 ~]# echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z
[root@cent7 ~]# 
[root@cent7 ~]# echo {000..20..2}
000 002 004 006 008 010 012 014 016 018 020
cp hello.sh{,bak}
tab   命令補全
      判斷某個命令是否安裝
[root@cent7 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
定義命令的全路徑,避免每次敲命令要使用全部路徑

使用頻率  1星 

command 2Tab  所有命令行補全
string2Tab  以string開頭命令        使用頻率超5星
/2Tab  顯示所有根目錄下一級目錄,包括隱藏目錄
./2Tab  當前目錄下子目錄,包括隱藏目錄         ls -da  ./*
*2Tab  當前目錄下子目錄,不包括隱藏目錄        ls -d  ./*
~2Tab  所有用戶列表
$2Tab  所有變量  
@2Tab  /etc/hosts記錄   (centos7不支持)
=2Tab  相當于ls –A  (CentOS 7 不支持)
命令行歷史  使用5星
!string 重復執行前面已string開頭的命令
!?string 重復前一個包含string的命令
^string 刪除上一條命令中的string
[root@CentOS68 ~]# ls /tmp/
epel.repo.bak         huan.txt        orbit-gdm   pulse-QRIoXpeAIz6g
functions-2017-03-23  keyring-BPBfln  orbit-root  pulse-rnm429VarZOM
[root@CentOS68 ~]# 
[root@CentOS68 ~]# ^tmp/
^string1^string2 將上一條命令中的第一個string1替換為string2
[root@CentOS68 ~]# ls /tmp/
epel.repo.bak         huan.txt        orbit-gdm   pulse-QRIoXpeAIz6g
functions-2017-03-23  keyring-BPBfln  orbit-root  pulse-rnm429VarZOM
[root@CentOS68 ~]# 
[root@CentOS68 ~]# 
[root@CentOS68 ~]# ^tmp^etc
!!:gs/string1/string2 將上一條命令中所有的string1都替換為 string2
[root@CentOS68 ~]# ls /tmp/ /tmp/
/tmp/:
epel.repo.bak         huan.txt        orbit-gdm   pulse-QRIoXpeAIz6g
functions-2017-03-23  keyring-BPBfln  orbit-root  pulse-rnm429VarZOM
/tmp/:
epel.repo.bak         huan.txt        orbit-gdm   pulse-QRIoXpeAIz6g
functions-2017-03-23  keyring-BPBfln  orbit-root  pulse-rnm429VarZOM
[root@CentOS68 ~]# !!:gs/tmp/opt
ls /opt/ /opt/
/opt/:
rh
/opt/:
rh
command !^ : 利用上一個命令的第一個參數做cmd的參數
ls /tmp  /opt
ls !^
command !$ : 利用上一個命令的最后一個參數做cmd的參數
ls /tmp /opt/
ls !$
command !* : 利用上一個命令的全部參數做cmd的參數
ls /tmp /opt
ls !*
command !:n : 利用上一個命令的第n個參數做cmd的參數
ls /tmp /opt
ls !:1
command !n:^ 調用第n條命令的第一個參數
 ls !505:^
command !n:$ 調用第n條命令的最后一個參數
ls !505:$
command !n:m 調用第n條命令的第m個參數
ls !505:2
command !n:* 調用第n條命令的所有參數
ls !505:*
command !string:^ 從命令歷史中搜索以 string 開頭的命令,并獲取它的第一個參數
ls !ls:^
command !string:$ 從命令歷史中搜索以 string 開頭的命令,并獲取它的最后一個參數
[root@CentOS68 ~]# ls /tmp/ /opt/
/opt/:
rh
/tmp/:
epel.repo.bak         huan.txt        orbit-gdm   pulse-QRIoXpeAIz6g
functions-2017-03-23  keyring-BPBfln  orbit-root  pulse-rnm429VarZOM
[root@CentOS68 ~]# ls !ls:$
ls /opt/
rh
command !string:n 從命令歷史中搜索以 string 開頭的命令,并獲取它的第n個參數
[root@CentOS68 ~]# ls /tmp/ /opt/
/opt/:
rh
/tmp/:
epel.repo.bak         huan.txt        orbit-gdm   pulse-QRIoXpeAIz6g
functions-2017-03-23  keyring-BPBfln  orbit-root  pulse-rnm429VarZOM
[root@CentOS68 ~]# 
[root@CentOS68 ~]# 
[root@CentOS68 ~]# ls !ls:2
ls /opt/
rh
command !string:* 從命令歷史中搜索以 string 開頭的命令,并獲取它的所有參數
[root@CentOS68 ~]# ls /tmp/ /opt/
/opt/:
rh
/tmp/:
epel.repo.bak         huan.txt        orbit-gdm   pulse-QRIoXpeAIz6g
functions-2017-03-23  keyring-BPBfln  orbit-root  pulse-rnm429VarZOM
[root@CentOS68 ~]# 
[root@CentOS68 ~]# ls !ls:*
ls /tmp/ /opt/
/opt/:
rh
/tmp/:
epel.repo.bak         huan.txt        orbit-gdm   pulse-QRIoXpeAIz6g
functions-2017-03-23  keyring-BPBf
正則表達式  ^$ 位置錨定 開始和結束 
            *  *前面的字符出現任意次
文件通配符  *  匹配所有格式的文件
history 默認最多只能記錄1000命令
命令歷史一般記錄在.bash_history文件中
當前shell中的歷史記錄會被記錄在內存中,只有退出之后才會保存在.bash_history中
-a
Append
$HISTSIZE 修改history存儲條數
$HISTFILE 指定歷史文件的存放位置
$HISTFILESIZE 指定歷史文件的命令的存儲條數
HISTTIMEFORMAT=“%F %T “ 顯示每條命令的具體執行時間
HISTIGNORE=  把某些命令敏感的字符串給屏蔽掉不予顯示
環境變量:HISTCONTROL
    ignoredups  默認,忽略重復的命令,連續且相同為“重復”
    ignorespace 忽略所有以空白開頭的命令
    ignoreboth  相當于ignoredups, ignorespace的組合
    erasedups   刪除重復命令
export magedu=123 頂一個環境變量
使用頻率超五星
Ctrl + l    清屏,相當于clear命令
Ctrl + c    終止命令
Ctrl + xx    光標在命令行首和光標之間移動
Ctrl + a    光標移到命令行首,相當于Home
Ctrl + e    光標移到命令行尾,相當于End
使用頻率 :2星
Ctrl + u    從光標處刪除至命令行首
Ctrl + k    從光標處刪除至命令行尾
date cat ls  cp mv  cal w rm 
more less
who whoami
nano
pwd
useradd
help
history
bash
enable
alias
shutdown
which
type
init 
runlevel
poweroff
echo
passwd
touch
cd
whatis
lscpu
cat /proc/cpuinfo  查看cpu的信息
顯示當前時間
Linux部分命令及使用
如果內部命令獲取幫助 可以使用help CMD
less 命令 查看文件內容
類似于cat 或者more
字體顏色改變
Linux部分命令及使用
man –f keyword 查看某個命令使用幫助在哪個章節里面
man
space 向文件尾部翻屏
b   向文件首部翻屏
enter  向下一行一行翻 
y  向上一行一行翻
1G 回到文件首部
G  回到文件尾部
/keywork  向下搜索 n 向下 N 向上
?向上搜索
LVS 負載均衡 
做運維 自己寫代碼 shell Python JAVA

一定要有幫助文檔readme  

備注(運用了部分筆記)

 

原創文章,作者:wangqiang,如若轉載,請注明出處:http://www.www58058.com/73018

(0)
wangqiangwangqiang
上一篇 2017-04-09 20:37
下一篇 2017-04-09 22:19

相關推薦

  • 馬哥網絡教育班第21期+第六周課程練習

    請詳細總結vim編輯器的使用并完成以下練習題 1、復制/etc/rc.d/rc.sysinit文件至/tmp目錄,將/tmp/rc.sysinit文件中的以至少一個空白字符開頭的行的行首加#; [root@localhost ~]# cp /etc/rc.d/rc.sysinit /tmp/ [root@localho…

    Linux干貨 2016-08-02
  • 文件管理及常用命令(一)

    cat命令: -n 增加行號 空行也增加行號          [root@localhost ~]# cat f1     abcd     abc…

    Linux干貨 2016-08-08
  • 第三周作業

    1. 列出當前系統上所有已經登錄的用戶的用戶名,注意:同一個用戶登錄多次則顯示一次即可。 who | cut -d' ' -f1 | sort -u 2. 取出最后登錄當前系統的用戶的相關信息 grep  "$(who …

    Linux干貨 2016-12-19
  • 馬哥教育網絡班21期+第四周博客作業

    1、復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限。 [root@C67-X64-A0 ~]# cp -a /etc/skel/ /home/tuser1 [root@C67-X64-A0 ~]# ls&nb…

    Linux干貨 2016-07-29
  • rsync3.0 (初稿 逐步完善)

    實驗環境為 centos 7.2 系統   CentOS Linux release 7.2.1511 (Core)   主機  ip               10.1.250.19 客…

    Linux干貨 2016-06-03
  • 如何解決生產機上php代碼連接mysql報錯的故障

    大家好: 今天分享一則當生產機上的網站php代碼不能連接Mysql服務器時怎么辦? 當LNMP的網站建立好后,我們需要測試網站中的php代碼。但發現如下報錯怎么辦? 解決方法如下:  mysql> show databases; +——————–+ | Dat…

    Linux干貨 2016-12-18
欧美性久久久久