深入浅出了解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变量配置

变量配置的语法如下:

代码小浣熊 代码小浣熊

代码小浣熊是基于商汤大语言模型的软件智能研发助手,覆盖软件需求分析、架构设计、代码编写、软件测试等环节

代码小浣熊 51 查看详情 代码小浣熊

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 4completion-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  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  and C-J will terminate an incremental search.keymap#Sets Readline'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-newlineIf 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'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'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'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-argumentMeta-Rubout: backward-kill-word M-DEL is bound to the function backward-kill-wordControl-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终端大小写敏感问题(附代码)的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/546177.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
Star量近8万,大火AutoGPT星标超PyTorch,网友:看清它的局限性
上一篇 2025年11月9日 17:44:02
java枚举类怎么使用
下一篇 2025年11月9日 17:44:09

相关推荐

  • Python命令怎样使用profile分析脚本性能 Python命令性能分析的基础教程

    使用Python的cProfile模块分析脚本性能最直接的方式是通过命令行执行python -m cProfile your_script.py,它会输出每个函数的调用次数、总耗时、累积耗时等关键指标,帮助定位性能瓶颈;为进一步分析,可将结果保存为文件python -m cProfile -o ou…

    2026年5月10日
    000
  • c++如何实现UDP通信_c++基于UDP的网络通信示例

    UDP通信基于套接字实现,适用于实时性要求高的场景。1. 流程包括创建套接字、绑定地址(接收方)、发送(sendto)与接收(recvfrom)数据、关闭套接字;2. 服务端监听指定端口,接收客户端消息并回传;3. 客户端发送消息至服务端并接收响应;4. 跨平台需处理Winsock初始化与库链接,编…

    2026年5月10日
    000
  • 谷歌浏览器如何截图 谷歌浏览器页面截图技巧

    谷歌浏览器如何截图 谷歌浏览器页面截图技巧谷歌浏览器如何截图 谷歌浏览器页面截图技巧谷歌浏览器如何截图 谷歌浏览器页面截图技巧谷歌浏览器如何截图 谷歌浏览器页面截图技巧

    使用谷歌浏览器的开发者工具截图步骤:1. 按ctrl+shift+i(windows/linux)或cmd+option+i(mac)打开开发者工具。2. 点击右上角三个点,选择”更多工具”,再选择”截图”。3. 选择截取整个页面。推荐的谷歌浏览器扩展…

    2026年5月10日 用户投稿
    100
  • Golang使用Protobuf定义接口与消息格式

    Protobuf通过字段编号实现兼容性,新增字段可忽略、删除字段可保留编号,确保新旧版本互操作,支持服务独立演进。 在Golang项目中,利用Protobuf定义接口和消息格式,本质上是为服务间通信构建了一套高效、类型安全且跨语言的契约。它让数据结构清晰可见,RPC调用标准化,极大地简化了分布式系统…

    2026年5月10日
    000
  • pycharm解析器怎么添加 解析器添加详细流程

    在pycharm中添加解析器的步骤包括:1) 打开pycharm并进入设置,2) 选择project interpreter,3) 点击齿轮图标并选择add,4) 选择解析器类型并配置路径,5) 点击ok完成添加。添加解析器后,选择合适的类型和版本,配置环境变量,并利用解析器的功能提高开发效率。 在…

    2026年5月10日
    000
  • HTML文档如何工作?如何编辑HTML格式文件?

    HTML文档如何工作?如何编辑HTML格式文件?HTML文档如何工作?如何编辑HTML格式文件?HTML文档如何工作?如何编辑HTML格式文件?HTML文档如何工作?如何编辑HTML格式文件?

    浏览器解析和渲染html的过程包括:1. 解析html构建dom树;2. 结合css构建渲染树;3. 布局计算元素位置;4. 绘制像素到屏幕。编辑html可使用记事本、vs code、sublime text等文本或代码编辑器,其中vs code因语法高亮、自动补全和插件生态成为主流选择。标准htm…

    2026年5月10日 用户投稿
    000
  • Python官网用户调查的参与方式_Python官网反馈提交详细教程

    答案是通过访问Python官网新闻页面、邮件邀请链接或GitHub仓库提交反馈。具体为:访问官网查找用户调查公告,或点击邮件中的专属链接参与,在GitHub的cpython仓库提交技术建议,并注意如实填写问卷与保护隐私。 如果您希望参与Python官网的用户调查并提交反馈,可以通过官方指定的渠道完成…

    2026年5月10日
    000
  • JavaScript Electron桌面应用

    答案:使用JavaScript开发%ignore_a_1%桌面应用需结合Web技术与Node.js,通过主进程管理窗口、渲染进程展示界面,并利用IPC通信,调用系统功能如文件对话框,最后用electron-builder打包发布,注意安全与进程职责分离。 用JavaScript开发Electron桌…

    2026年5月10日
    000
  • php代码如何操作JSON数据_php代码解析和生成JSON的方法

    答案:PHP中处理JSON需使用json_encode()和json_decode()函数。1、将数组转为JSON字符串时,用json_encode()并检查返回值是否为false;2、解析JSON字符串时,调用json_decode()并设第二参数为true返回数组,false则返回对象;3、处理…

    2026年5月10日
    000
  • Linux文件系统iostat命令使用技巧

    Linux文件系统iostat命令使用技巧Linux文件系统iostat命令使用技巧Linux文件系统iostat命令使用技巧Linux文件系统iostat命令使用技巧

    iostat是Linux系统中用于监控I/O设备负载的关键工具,能分析磁盘性能并识别瓶颈。默认输出包括CPU使用率和设备I/O统计,分为系统启动以来的平均值和当前采样周期数据。核心指标有:%util反映设备利用率,持续接近100%可能表示I/O瓶颈;await为平均I/O等待时间,过高说明响应变慢;…

    2026年5月10日 用户投稿
    000
  • 如何测试html5编码_测试HTML5页面编码兼容性方法【编码测试】

    HTML5页面编码兼容性测试需五步:一查meta charset是否正确且前置;二验HTTP响应头Content-Type charset是否为utf-8;三用file或chardet工具探测实际编码;四跨浏览器测试URL参数中中文、Emoji解析;五通过W3C验证服务检查编码声明与字节一致性。 如…

    2026年5月10日
    100
  • 后缀php怎么打开_php文件打开方式与运行环境搭建指南

    要打开PHP文件需根据用途选择方式:查看代码可用文本编辑器或IDE,运行则需服务器环境。推荐新手使用XAMPP、WAMP等集成环境,将文件放入htdocs目录后访问localhost;开发者可利用PHP内置服务器,命令行执行php -S localhost:8000运行;高级用户可手动配置Apach…

    2026年5月10日
    000
  • Go语言:检查预编译库的构建版本与平台信息

    本文详细介绍了如何利用go语言内置的`go tool pack`工具,从预编译的go静态库(`.a`文件)中提取其构建信息,包括go编译器版本、操作系统和cpu架构。当`go build`因库版本不匹配而失败时,此方法能帮助开发者准确诊断问题,确保构建环境与库的兼容性。 在Go语言的开发实践中,我们…

    2026年5月10日
    000
  • 解决Python脚本中相对路径文件找不到的常见问题与策略

    本文旨在解决python脚本中因相对路径处理不当导致的文件找不到错误,尤其是在项目迁移后。文章将深入探讨python中相对路径的工作原理、当前工作目录(cwd)的影响,并提供使用`os.getcwd()`诊断问题以及利用`os.path.dirname(__file__)`结合`os.path.jo…

    2026年5月10日
    000
  • Golang如何提升TCP长连接处理效率_Golang TCP长连接处理性能优化实践详解

    答案:通过非阻塞I/O、单Goroutine双工模型、sync.Pool对象复用、TCP_NODELAY优化及高效心跳管理,结合系统调优,可显著提升Golang百万级TCP长连接处理效率。 在高并发网络服务场景中,TCP长连接的处理效率直接影响系统的吞吐能力和资源消耗。Golang凭借其轻量级Gor…

    2026年5月10日
    000
  • C++内存检测工具 Valgrind使用实践指南

    Valgrind是一款主要用于Linux和macOS的内存调试工具,可检测内存泄漏、越界访问、未初始化内存使用等问题,通过memcheck工具结合–leak-check=full、–track-origins=yes等选项进行详细分析,需编译时添加-g选项以支持调试信息,虽然…

    2026年5月10日
    000
  • php源码怎么运行手机_php源码手机运行环境搭建步骤【教程】

    可在手机上通过特定工具运行PHP源码。首先选择支持PHP的移动应用,安卓用户可安装UserLAnd或KSWEB,iOS用户可尝试iSH Shell或a-Shell;然后配置本地服务器环境,启动HTTP和PHP服务,将PHP文件放入指定根目录;接着可通过Termux搭建完整开发环境,更新包列表并安装P…

    2026年5月10日
    200
  • PHP动态网页数据库备份恢复_PHP动态网页MySQL数据库备份教程

    答案:PHP动态网页的MySQL数据库备份与恢复需通过定期导出SQL文件并安全存储来保障数据安全,核心方法包括使用mysqldump命令行工具实现高效灵活的自动化备份,利用phpMyAdmin图形化工具进行手动导出导入以降低操作门槛,以及通过PHP脚本调用系统命令将备份过程集成到应用中;恢复时可采用…

    2026年5月10日
    000
  • 解决Go语言中GOPATH未设置错误及工作区配置指南

    本文旨在解决go语言开发中常见的“gopath not set”错误,并提供详细的go工作区配置指南。内容涵盖`gopath`环境变量的设置、go项目目录结构、`path`变量的扩展,以及一些高级配置技巧,旨在帮助开发者建立一个高效、规范的go开发环境,确保包的下载、编译和运行顺利进行。 Go语言在…

    2026年5月10日
    000
  • Linux用scp命令上传HTML文件到远程服务器

    使用scp命令可安全上传HTML文件至远程服务器:1、上传单个文件需指定源路径与目标地址;2、批量上传可用*.html通配符;3、递归上传目录需加-r参数;4、非默认端口需用-P指定端口号,依次执行并输入密码即可完成传输。 如果您需要将本地的HTML文件上传到远程服务器,并且拥有SSH访问权限,可以…

    2026年5月10日
    000

发表回复

登录后才能评论
关注微信