ITPub博客

首页 > Linux操作系统 > Linux操作系统 > [20220826]ls显示文件不区分大小写.txt

[20220826]ls显示文件不区分大小写.txt

原创 Linux操作系统 作者:lfree 时间:2022-08-29 20:53:28 0 删除 编辑

[20220826]ls显示文件不区分大小写.txt

--//前几天看的,链接https://www.cyberciti.biz/faq/ls-command-case-insensitive-mode-search-pattern-linux-unix/
--//如果不看链接内容,我想到的方法就是grep -i 过滤.
$ ls -l | grep -i server

--//链接提供几种方法:
$ shopt -s nocaseglob

--//支持这个功能与bash 版本有关,低版本不支持。关闭使用shopt -u nocaseglob
--//作者还提到使用find的方法使用-iname参数,做一个记录:
find /dir/ -iname "*service*.pdf" -ls

--//简单测试如下,注在家里cygwin下测试的情况:

$ echo $BASH_VERSION
4.4.12(3)-release

$ ls -l *ex*
ls: cannot access '*ex*': No such file or directory

$ shopt -s nocaseglob

$ ls -l *ex*
-rwxr-xr-x 1 Administrator None 2881536 2019-05-18 21:56:35 EXPDAT.DMP

$ shopt -u nocaseglob

$ find . -iname "*.dmp" -ls
2533274790570810   2816 -rwxr-xr-x   1  Administrator None      2881536 May 18  2019 ./EXPDAT.DMP

--//查看man find手册。

$ find . -name "*.dmp" -ls

$ man find
...
-iname pattern
    Like -name, but the match is case insensitive.  For example, the patterns `fo*' and `F??' match the file names
    `Foo', `FOO', `foo',  `fOo',  etc.    The  pattern `*foo*` will also match a file called '.foobar'.

--//感觉find -iname相对实用一些。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-2912506/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    4006
  • 访问量
    7969544