日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux 历史命令快捷键,Linux历史命令及bash快捷键

發布時間:2025/3/12 linux 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux 历史命令快捷键,Linux历史命令及bash快捷键 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本文環境 Centos7

1.歷史命令

1.1 在使用linux中熟練的使用歷史命令,能給我很多便捷,下面我來總結一些常用的一些歷史命令。

a) 執行上一條命令,這個很重要 ,執行上一條命令有四種方法,如下:

[root@CentOS-7-64data]#

[root@CentOS-7-64 data]# ls[a-z] kas kokoa l1234bd l1234bd1dada l12k l12ka l2a

當然這個命令很簡單,但是命令很復雜呢?使用 ↑ ,ctrl+p ,!-1 ,!! 這四種方式可以執行上條命令

[root@CentOS-7-64 data]# !!

ls[a-z] kas kokoa l1234bd l1234bd1dada l12k l12ka l2a

[root@CentOS-7-64 data]# ls # 我這里按的是 ctrl+p

[a-z] kas kokoa l1234bd l1234bd1dada l12k l12ka l2a

[root@CentOS-7-64 data]# !-1

ls[a-z] kas kokoa l1234bd l1234bd1dada l12k l12ka l2a

[root@CentOS-7-64 data]# ls# 這里是 ↑ 鍵

[a-z] kas kokoa l1234bd l1234bd1dada l12k l12ka l2a

[root@CentOS-7-64 data]#

b) 在歷史命令中執行最新一條以cat開頭的命令,要執行以什么開頭的命令,在嘆號后面加上你要執行的命令,執行的是最后一條以cat開頭的命令? ? ? ? ? 用法? !cat

[root@CentOS-7-64 data]# !cat

catkas

hello world

hello world

[root@CentOS-7-64 data]#

c) 在歷史命令中執行包含red的命令,這條命不同于上條,上條是開頭,這條是包含,使用方法:

!?red? ?!?+你要包含的命令

[root@CentOS-7-64 data]# cat /etc/redhat-release

CentOS Linux release7.7.1908(Core)

[root@CentOS-7-64 data]# !?redcat /etc/redhat-release

CentOS Linux release7.7.1908(Core)

[root@CentOS-7-64 data]#

d) 打印以kas開頭的命令,只打印不執行? 方法? !command:p

[root@CentOS-7-64 data]# !kas:p

kas

e)?執行前一條命令(去除參數)并打印出命令? 方法 !:0

[root@CentOS-7-64 data]# catkas

hello world

hello world

[root@CentOS-7-64 data]# !:0kokoacatkokoa

hello china

hello china

[root@CentOS-7-64 data]#

f) 得到前一個命令的第一個參數并打印命令? ?用法? !:1

[root@CentOS-7-64 data]# catkokoa

hello china

hello china

[root@CentOS-7-64 data]# vim !:1vim kokoa

[root@CentOS-7-64 data]#

g)??要重新調用前一個命令中最后一個參數并打印命令? ?有幾種方法? 我就寫我常用的? 用法 !$? Esc + .? 英文點

[root@CentOS-7-64 data]# !grep

grep "hello"kokoa kas

kokoa:hello china

kokoa:hello china

kas:hello world

kas:hello world

[root@CentOS-7-64 data]# vim !$

vim kas

[root@CentOS-7-64 data]#

Esc + 點? ?得到前一個命令的參數

[root@CentOS-7-64 data]# catkokoa

hello china

hello china

[root@CentOS-7-64 data]# vim kokoa

1.2 用好這些歷史命令的正確方式能給我們的工作很大的便利,還有很多類似的命令,我就不一一演示了,就寫在下面了

!$:p? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?打印上一條命令的最后一個參數

!*:p? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 打印上一條命令的所有參數

!^:p? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?打印上一條命令的第一個參數

^command? ? ? ? ? ? ? ? ? ? ?  ? ? ? ? ??刪除上一條命令中的第一個command,并執行刪除 command 后的結果

^command1^command2? ? ? ? ? ? ? ? 將上一條命令中的第一個command1替換為command2

!:gs/command1/command2? ? ? ? ? ? 將上一條命令中所有的command1都替換為 command

ctrl + r? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 搜索歷史命令? ? ctrl+g? ? ?退出搜索

command !^? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 將上個命令的第一個參數作command的參數

command !$? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 將上個命令的最后一個參數作command的參數

command !*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?將上個命令的所有參數作command的參數

command !:n? ? ? ? ? ? ?      將上個命令的第n個參數作command的參數

command !n:^? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?獲取第n條命令的第一個參數

command !n:$? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?獲取第n條命令的最后一個參數

command !n:m? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?獲取第n條命令的第m個參數

command !n:*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?獲取第n條命令的所有參數

command !cmd:^? ? ? ? ? ? ? ? ? ? ? ? ? ? 在命令歷史中搜索以 cmd 開頭的命令,并獲取它的第一 個參數

command !cmd:$? ? ? ? ? ? ? ? ? ? ? ? ? ? 在命令歷史中搜索以 cmd 開頭的命令,并獲取它的最后一 個參數

command !cmd:n? ? ? ? ? ? ? ? ? ? ? ? ? ? 在命令歷史中搜索以 cmd 開頭的命令,并獲取它的第n 個參數

command !cmd:*? ? ? ? ? ? ? ? ? ? ? ? ? ? 在命令歷史中搜索以 cmd 開頭的命令,并獲取它的所有 參數

1.3 歷史命令的環境變量

HISTSIZE? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?記錄歷史命令條數

HISTFILE? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?記錄歷史命令的文件

HISTFILESIZE         命令歷史文件記錄歷史的條數

HISTTIMEFORMAT? ? ? ? ? ? ? ? ? ? ? ? 顯示歷史命令時間? ?這個很有用? ? 如:HISTTIMEFORMAT="%T-%F? ? ? "? ?后面留了幾個空格,你試試不留空格的效果?

HISTIGNORE

HISTCONTROL? ? ? ? ? ? ? ? ? ? ? ? ? ? ?以下是HISTCONTROL的值與效果

ignoredups? ? ? ? ? ? ? ? ? ?默認,忽略重復的命令,連續且相同為“重復”

ingorespace? ? ? ? ? ? ? ? ?不記錄以空格開頭的命令

ingoreboth? ? ? ? ? ? ? ? ? ? 是以上兩個值的效果,不記錄空格開頭,忽略重復

erasedups? ? ? ? ? ? ? ? ? ? ?刪除重復命令

2. bash快捷鍵? 常用的很多沒列出

ctrl+l? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 清屏

ctrl+y??          將刪除的粘貼到光標處

ctrl+z          掛起

ctrl+c?         ? 強行終止

ctrl+s          鎖定屏幕,組織輸出

ctrl+t          交換字符,將光標前的字符與光標處的字符交換

ctrl+q          對應以上ctrl+s的命令,對ctrl+s進行恢復

ctrl+o          執行當前命令,并重新顯示本命令

ctrl+e          將光標移至行尾

ctrl+a          將光標移至行首

ctrl+u          刪除到行首

ctrl+k          刪除到行尾

ctrl+d          刪除光標上的字符

ctrl+h          刪除光標前的字符

ctrl+w          向左刪除至單詞首

alt+r          刪除整行

alt+f          光標向右移至單詞尾

alt+b          光標向左移至單詞首

alt+t          將光標處的單詞與前一個單詞換位置

alt+d          向左刪除至單詞首

總結

以上是生活随笔為你收集整理的linux 历史命令快捷键,Linux历史命令及bash快捷键的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。