使用 ls 选择性地列出文件
Selective listing of files using ls
我在名为
的目录中有一组文件
美国广播公司
data.txt
你好
你好1
hello1.text
hello.txt
我只想列出文件 hello 和 hello1。
我试过使用这个命令ls -lrt hello* | ls -lrt !(hello*.*)
我得到的输出是
abc
data.txt
hello
hello1
管道功能在这种情况下不起作用。
请帮我解决这个问题
如果我理解正确:
ls hello*
或
ls -l hello*
既然你用 grep 标记了,试试这个:
ls -l |grep 'hello1\?$'
如果数字可以是动态的,试试这个
ls -l|grep 'hello[0-9]*$'
使用 bash 扩展 pattern matching:
$ shopt -s extglob
$ ls hello*([^.])
hello hello1
该模式是 "hello" 后跟零个或多个非点字符。
我在名为
的目录中有一组文件
美国广播公司
data.txt
你好
你好1
hello1.text
hello.txt
我只想列出文件 hello 和 hello1。
我试过使用这个命令ls -lrt hello* | ls -lrt !(hello*.*)
我得到的输出是
abc
data.txt
hello
hello1
管道功能在这种情况下不起作用。
请帮我解决这个问题
如果我理解正确:
ls hello*
或
ls -l hello*
既然你用 grep 标记了,试试这个:
ls -l |grep 'hello1\?$'
如果数字可以是动态的,试试这个
ls -l|grep 'hello[0-9]*$'
使用 bash 扩展 pattern matching:
$ shopt -s extglob
$ ls hello*([^.])
hello hello1
该模式是 "hello" 后跟零个或多个非点字符。