unix列出名称中带有句号的文件
我有4个文件:命名约定如下:unix列出名称中带有句号的文件,unix,ls,Unix,Ls,我有4个文件:命名约定如下: hello.account.sub1.001 hello.account.sub2.001 hello.account.sub3.001 hello.account.sub4.001 如果我使用ls-l hello.account*001搜索文件,则不存在任何问题 但是,使用ls-l hello.account.*.001时存在问题 系统抱怨没有这样的文件或目录 我假设系统认为hello.account.*.001是一个文件 这让我感兴趣,所以我问:
hello.account.sub1.001
hello.account.sub2.001
hello.account.sub3.001
hello.account.sub4.001
如果我使用ls-l hello.account*001
搜索文件,则不存在任何问题
但是,使用ls-l hello.account.*.001时存在问题
系统抱怨没有这样的文件或目录
我假设系统认为hello.account.*.001是一个文件
这让我感兴趣,所以我问:如果将句号指定为搜索条件,如何搜索文件
非常感谢是在实际执行命令之前由shell完成的(在您的例子中,例如ls
)。以下工作:
$ ksh --version
version sh (AT&T Research) 93t+ 2010-06-21
$ ls -l hello.account.*.001
-rw-r--r-- 1 andreas users 0 Jul 22 03:59 hello.account.sub1.001
-rw-r--r-- 1 andreas users 0 Jul 22 03:59 hello.account.sub2.001
-rw-r--r-- 1 andreas users 0 Jul 22 03:59 hello.account.sub3.001
-rw-r--r-- 1 andreas users 0 Jul 22 03:59 hello.account.sub4.001
但以下情况并非如此:
$ ls -l "hello.account.*.001"
ls: hello.account.*.001: No such file or directory
原因是在第一种情况下,shell在执行ls
-ls
之前展开文件名模式,然后将看到四个不同的文件名作为参数传递
在第二种情况下,由于文件名模式是用双引号转义的,ls
获得模式本身的传递(它不会进一步展开-它会查找名为hello.account.*.001
)的文件。在实际执行命令之前由shell完成(在您的情况下,例如ls
)。以下操作有效:
$ ksh --version
version sh (AT&T Research) 93t+ 2010-06-21
$ ls -l hello.account.*.001
-rw-r--r-- 1 andreas users 0 Jul 22 03:59 hello.account.sub1.001
-rw-r--r-- 1 andreas users 0 Jul 22 03:59 hello.account.sub2.001
-rw-r--r-- 1 andreas users 0 Jul 22 03:59 hello.account.sub3.001
-rw-r--r-- 1 andreas users 0 Jul 22 03:59 hello.account.sub4.001
但以下情况并非如此:
$ ls -l "hello.account.*.001"
ls: hello.account.*.001: No such file or directory
原因是在第一种情况下,shell在执行ls
-ls
之前展开文件名模式,然后将看到四个不同的文件名作为参数传递
在第二种情况下,由于文件名模式是用双引号转义的,ls
获取传递的模式本身(它不会进一步展开-它查找名为hello.account.*.001
)系统抱怨没有这样的文件或目录对我有效。你使用的是哪个Shell?应该仍然有效-文件名globbing由Shell完成,除非模式被转义,所以你应该仍然可以看到所有四个文件。如果你使用ls-l“hello.account.*.001”,情况会有所不同
由于我在学校的unix系统中遇到了这个问题,我目前无法测试它。我想我可能会在文件名中添加引号。无论如何,感谢您的友好回复!系统抱怨没有这样的文件或目录对我有效。
-不,这对我有效。您使用的是哪个Shell?应该仍然有效-文件名全局搜索由Shell完成,除非e模式是转义的,所以您应该仍然可以看到所有四个文件。如果您执行了ls-l“hello.account.*.001”
则会有所不同,因为我在学校的unix系统中面临这个问题,我目前无法测试它。我想我可以在文件名中添加引号。无论如何,谢谢您的回复!