搜尋
首頁運維linux運維深入淺出了解Linux和MacOS終端機大小寫敏感問題(附程式碼)

之前的文章《一文講解ajax實現無刷新上傳和下載(代碼詳解)》中,給大家了解了ajax實現無刷新上傳和下載。以下這篇文章給大家了解Linux和MacOS終端機大小寫敏感問題,夥伴們來看看吧。

深入淺出了解Linux和MacOS終端機大小寫敏感問題(附程式碼)

Linux和MacOS終端機提示大小寫不敏感

開啟終端,並cd到使用者home 目錄,輸入:

echo "set completion-ignore-case on" >> .inputrc

關閉再重新開啟終端即可

如果你只想快速解決上面的問題,直接看第三部分即可。

inputrc 檔案介紹

Bash和其它大多數shell使用Readline函式庫作為其輸入相關的函式庫。 Readline庫有一些預設的鍵盤映射,除此之外,也可以透過修改inputrc檔案來自訂鍵盤映射。

inputrc檔案時Readline庫的啟動文件,當使用Readline作為輸入庫的程式啟動時,它會自動讀取inputrc設定文件,初始化自訂的鍵盤映射。

inputrc檔案的位置由shell的環境變數INPUTRC控制,如果該變數沒有設置,缺省的inputrc檔案的路徑是~/.inputrc

如果該檔案~/.inputrc不存在,就會使用系統層級(對所有使用者生效)的inputrc檔案/etc/inputrc。如果某個使用者需要修改系統預設的 inputrc配置,可以改變~/.inputrc,這樣會覆寫系統的預設配置。

關於如何編輯inputrc檔案的信息,運行info bash,參考bashinfo頁的Readline Init File這一節,執行info readline以參考readline自己的info頁。

inputrc 配置

inputrc檔案中,有兩種​​設定:一種是inputrc變量,一種是鍵盤映射。請注意,在設定該檔案時,註解必須佔單獨的一行,否則可能會有問題。

inputrc變數設定

變數配置的語法如下:

set variable value

常見的變數與設定如下:

completion-ignore-case
#如果设置为开(on),在自动补全时不区分大小写。该配置默认是关。

show-all-if-ambiguous
#这个配置该变了自动补全函数的默认行为。如果设置为开(on),当自动补全的结果有一个以上时,会直接列出这些结果。如果设置为关(off),就会提示一个beep蜂鸣声,当再按下tab时才会列出自动补全的结果。默认这项配置为关。

bell-style
#Controls what happens when Readline wants to ring the terminal bell. If set to ‘none’, Readline never rings the bell. If set to ‘visible’, Readline uses a visible bell if one is available. If set to ‘audible’ (the default), Readline attempts to ring the terminal's bell.

bind-tty-special-chars
#If set to ‘on’, Readline attempts to bind the control characters treated specially by the kernel's terminal driver to their Readline equivalents.

comment-begin
#The string to insert at the beginning of the line when the insert-comment command is executed. The default value is "#".
completion-prefix-display-length

#When set to a value greater than zero, common prefixes longer than this value are replaced with an ellipsis when displaying possible completions.
#e.g. set completion-prefix-display-length 4

completion-query-items
#The number of possible completions that determines when the user is asked whether the list of possibilities should be displayed. If the number of possible completions is greater than this value, Readline will ask the user whether or not he wishes to view them; otherwise, they are simply listed. This variable must be set to an integer value greater than or equal to 0. A negative value means Readline should never ask. The default limit is 100.

convert-meta
#If set to ‘on’, Readline will convert characters with the eighth bit set to an ascii key sequence by stripping the eighth bit and prefixing an <ESC> character, converting them to a meta-prefixed key sequence. The default value is ‘on’.

disable-completion
#If set to ‘On’, Readline will inhibit word completion. Completion characters will be inserted into the line as if they had been mapped to self-insert. The default is ‘off’.

editing-mode
#The editing-mode variable controls which default set of key bindings is used. By default, Readline starts up in Emacs editing mode, where the keystrokes are most similar to Emacs. This variable can be set to either ‘emacs’ or ‘vi’.

echo-control-characters
#When set to ‘on’, on operating systems that indicate they support it, readline echoes a character corresponding to a signal generated from the keyboard. The default is ‘on’.

enable-keypad
#When set to ‘on’, Readline will try to enable the application keypad when it is called. Some systems need this to enable the arrow keys. The default is ‘off’.

enable-meta-key
#When set to ‘on’, Readline will try to enable any meta modifier key the terminal claims to support when it is called. On many terminals, the meta key is used to send eight-bit characters. The default is ‘on’.

expand-tilde
#If set to ‘on’, tilde expansion is performed when Readline attempts word completion. The default is ‘off’.

history-preserve-point
#If set to ‘on’, the history code attempts to place the point (the current cursor position) at the same location on each history line retrieved with previous-history or next-history. The default is ‘off’.

history-size
#Set the maximum number of history entries saved in the history list. If set to zero, the number of entries in the history list is not limited.

horizontal-scroll-mode
#This variable can be set to either ‘on’ or ‘off’. Setting it to ‘on’ means that the text of the lines being edited will scroll horizontally on a single screen line when they are longer than the width of the screen, instead of wrapping onto a new screen line. By default, this variable is set to ‘off’.

input-meta
#If set to ‘on’, Readline will enable eight-bit input (it will not clear the eighth bit in the characters it reads), regardless of what the terminal claims it can support. The default value is ‘off’. The name meta-flag is a synonym for this variable.

isearch-terminators
#The string of characters that should terminate an incremental search without subsequently executing the character as a command. If this variable has not been given a value, the characters <ESC> and C-J will terminate an incremental search.

keymap
#Sets Readline&#39;s idea of the current keymap for key binding commands. Acceptable keymap names are emacs, emacs-standard, emacs-meta, emacs-ctlx, vi, vi-move, vi-command, and vi-insert. vi is equivalent to vi-command; emacs is equivalent to emacs-standard. The default value is emacs. The value of the editing-mode variable also affects the default keymap.

mark-directories
#If set to ‘on’, completed directory names have a slash appended. The default is ‘on’.

mark-modified-lines
#This variable, when set to ‘on’, causes Readline to display an asterisk (*) at the start of history lines which have been modified. This variable is ‘off’ by default.

mark-symlinked-directories
#If set to ‘on’, completed names which are symbolic links to directories have a slash appended (subject to the value of mark-directories). The default is ‘off’.

match-hidden-files
#This variable, when set to ‘on’, causes Readline to match files whose names begin with a ‘.’ (hidden files) when performing filename completion, unless the leading ‘.’ is supplied by the user in the filename to be completed. This variable is ‘on’ by default.

output-meta
#If set to ‘on’, Readline will display characters with the eighth bit set directly rather than as a meta-prefixed escape sequence. The default is ‘off’.

page-completions
#If set to ‘on’, Readline uses an internal more-like pager to display a screenful of possible completions at a time. This variable is ‘on’ by default.

print-completions-horizontally
#If set to ‘on’, Readline will display completions with matches sorted horizontally in alphabetical order, rather than down the screen. The default is ‘off’.

revert-all-at-newline
If set to ‘on’, Readline will undo all changes to history lines before returning when accept-line is executed. By default, history lines can be modified and retain individual undo lists across calls to readline. The default is ‘off’.

show-all-if-unmodified
#This alters the default behavior of the completion functions in a fashion similar to show-all-if-ambiguous. If set to ‘on’, words which have more than one possible completion without any possible partial completion (the possible completions don&#39;t share a common prefix) cause the matches to be listed immediately instead of ringing the bell. The default value is ‘off’.

skip-completed-text
#If set to ‘on’, this alters the default completion behavior when inserting a single match into the line. It&#39;s only active when performing completion in the middle of a word. If enabled, readline does not insert characters from the completion that match characters after point in the word being completed, so portions of the word following the cursor are not duplicated. For instance, if this is enabled, attempting completion when the cursor is after the ‘e’ in ‘Makefile’ will result in ‘Makefile’ rather than ‘Makefilefile’, assuming there is a single possible completion. The default value is ‘off’.

visible-stats
#If set to ‘on’, a character denoting a file&#39;s type is appended to the filename when listing possible completions. The default is ‘off’.

#鍵盤映射配置

配置inputrc變數的語法如下:

keyname: function-name or macro

#keyname必须是英文,可以是Control-u、Control-k等。并且keyname和冒号之间不能有空格,如果有空格会被认为是keyname的一部分。keyname的写法多样,取决于自己的喜好。
#下面是一些键盘映射配置的例子:

Control-u: universal-argument C-u is bound to the function universal-argument

Meta-Rubout: backward-kill-word M-DEL is bound to the function backward-kill-word

Control-o: "> output" C-o is bound to run the macro expressed on the right hand side (that is, to insert the text ‘> output’ into the line)

Control-j: menu-complete C-j is bound to cycle through the available tab completions.

Control-k: menu-complete-backward C-k is bound to cycle backwards through the available tab completions.

"\t": menu-complete Use tab to cycle through all the possible completions.

"\C-p": history-search-backward Map control-p to allow search for completions to the current line from your history. e.g. type “git” and then hit control-p to cycle through all the recent git commands.

"\ep": history-search-backward Map escape-p to allow search for completions to the current line from your history. e.g. type “git” and then hit escape-p to cycle through all the recent git commands.

"\e[A": history-search-backward Map Up arrow to allow search for completions to the current line from your history. e.g. type “git” and then hit UP to cycle through all the recent git commands.

"\e[B": history-search-forward Map Down arrow to allow search for completions to the current line from your history. e.g. type “git” and then hit DOWN to cycle back through all the recent git commands.

"\C-d": kill-whole-line Map control-d to kill the whole line.

設定MacOS下自動補全不區分大小寫

透過上面的介紹,解決這個問題應該是綽綽有餘了。打開用戶主目錄下的文件~/.inputrc(如果沒有的話,就新建該文件),在其中添加如下配置:

# 设置自动补全不区分大小写
set completion-ignore-case on
# 当有一个以上自动补全结果时,直接列出,不用beep提示
set show-all-if-ambiguous on

保存該文件,然後,重啟命令行,就會發現自動補全不區分大小寫已經生效了。在網路上好多結果中,還需要多加一個下面的配置:

TAB: menu-complete

這個配置的目的是,在列出自動補全的結果之後,再按一次tab鍵,就會自動在自動補全清單中選擇,而不是一直顯示自動補全清單。

推薦學習:Mac OS入門教學Linux影片教學

#

以上是深入淺出了解Linux和MacOS終端機大小寫敏感問題(附程式碼)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文轉載於:禅境花园。如有侵權,請聯絡admin@php.cn刪除
Linux中的維護模式:系統管理員指南Linux中的維護模式:系統管理員指南Apr 26, 2025 am 12:20 AM

維護模式在Linux系統管理中扮演關鍵角色,幫助進行系統修復、升級和配置變更。 1.進入維護模式可以通過GRUB菜單選擇或使用命令“sudosystemctlisolaterescue.target”。 2.在維護模式下,可以執行文件系統修復和系統更新等操作。 3.高級用法包括重置root密碼等任務。 4.常見錯誤如無法進入維護模式或掛載文件系統,可通過檢查GRUB配置和使用fsck命令修復。

Linux中的維護模式:何時以及為什麼使用它Linux中的維護模式:何時以及為什麼使用它Apr 25, 2025 am 12:15 AM

使用Linux維護模式的時機和原因:1)系統啟動問題時,2)進行重大系統更新或升級時,3)執行文件系統維護時。維護模式提供安全、控制的環境,確保操作的安全性和效率,減少對用戶的影響,並增強系統的安全性。

Linux:基本命令和操作Linux:基本命令和操作Apr 24, 2025 am 12:20 AM

Linux中不可或缺的命令包括:1.ls:列出目錄內容;2.cd:改變工作目錄;3.mkdir:創建新目錄;4.rm:刪除文件或目錄;5.cp:複製文件或目錄;6.mv:移動或重命名文件或目錄。這些命令通過與內核交互執行操作,幫助用戶高效管理文件和系統。

Linux操作:管理文件,目錄和權限Linux操作:管理文件,目錄和權限Apr 23, 2025 am 12:19 AM

在Linux中,文件和目錄管理使用ls、cd、mkdir、rm、cp、mv命令,權限管理使用chmod、chown、chgrp命令。 1.文件和目錄管理命令如ls-l列出詳細信息,mkdir-p遞歸創建目錄。 2.權限管理命令如chmod755file設置文件權限,chownuserfile改變文件所有者,chgrpgroupfile改變文件所屬組。這些命令基於文件系統結構和用戶、組系統,通過系統調用和元數據實現操作和控制。

Linux中的維護模式是什麼?解釋了Linux中的維護模式是什麼?解釋了Apr 22, 2025 am 12:06 AM

MaintenancemodeInuxisAspecialBootenvironmentforforcalsystemmaintenancetasks.itallowsadMinistratorStoperFormTaskSlikerSettingPassingPassingPasswords,RepairingFilesystems,andRecoveringFrombootFailuresFailuresFailuresInamInimAlenimalenimalenrenmentrent.ToEnterMainterMainterMaintErmaintErmaintEncemememodeBoode,Interlecttheboo

Linux:深入研究其基本部分Linux:深入研究其基本部分Apr 21, 2025 am 12:03 AM

Linux的核心組件包括內核、文件系統、Shell、用戶空間與內核空間、設備驅動程序以及性能優化和最佳實踐。 1)內核是系統的核心,管理硬件、內存和進程。 2)文件系統組織數據,支持多種類型如ext4、Btrfs和XFS。 3)Shell是用戶與系統交互的命令中心,支持腳本編寫。 4)用戶空間與內核空間分離,確保系統穩定性。 5)設備驅動程序連接硬件與操作系統。 6)性能優化包括調整系統配置和遵循最佳實踐。

Linux體系結構:揭示5個基本組件Linux體系結構:揭示5個基本組件Apr 20, 2025 am 12:04 AM

Linux系統的五個基本組件是:1.內核,2.系統庫,3.系統實用程序,4.圖形用戶界面,5.應用程序。內核管理硬件資源,系統庫提供預編譯函數,系統實用程序用於系統管理,GUI提供可視化交互,應用程序利用這些組件實現功能。

Linux操作:利用維護模式Linux操作:利用維護模式Apr 19, 2025 am 12:08 AM

Linux的維護模式可以通過GRUB菜單進入,具體步驟為:1)在GRUB菜單中選擇內核並按'e'編輯,2)在'linux'行末添加'single'或'1',3)按Ctrl X啟動。維護模式提供了一個安全環境,適用於系統修復、重置密碼和系統升級等任務。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

EditPlus 中文破解版

EditPlus 中文破解版

體積小,語法高亮,不支援程式碼提示功能

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器