Question

I have 4 files: the naming convention is as follows:

hello.account.sub1.001  
hello.account.sub2.001  
hello.account.sub3.001  
hello.account.sub4.001 

If I use ls -l hello.account*001 to search files, no problem exists.

However, problem exists when using ls -l hello.account.*.001

The system complains that No such file or directory

I assume the system considers hello.account.*.001 is a single file.

This interests me so I ask: how can you search the file if a full stop is specified as searching criteria?

Many Thanks

Was it helpful?

Solution

Filename globbing is done by the shell, before actually executing the command (such as ls in your case). The following works:

$ 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

while the following does not:

$ ls -l "hello.account.*.001"
ls: hello.account.*.001: No such file or directory

The reason is that in the first case, the shell expands the file name pattern before executing ls - ls will then see four different file names passed as arguments.

In the second case, since the file name pattern is escaped with double quotes, ls gets the pattern itself passed (which ls does not further expand - it looks for a file with the name hello.account.*.001)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top