Vicky
Vicky

Reputation: 1338

ls -lR * lists all the files in current and subdirectories , but ls -lR *filename* does not list files in subdirectories

ls -lR * lists all the files in current and subdirectories , but ls -lR filename does not list files in subdirectories and only lists the files matching filename in current directory why so ? is there a way to list all the files whose name contains a particular text without using find and only using ls .

Upvotes: 0

Views: 11076

Answers (1)

JimNicholson
JimNicholson

Reputation: 351

According to the man page ls lists information about the filenames specified. The shell (bash, sh, zsh etc) expands the * to a list of filenames, so the command being execute is

ls -lR filename1 filename2 filename3 ...

If one of those filenames is a directory then ls will list it recursively.

In your second case

ls -lR filename

If that filename is the name of a directory, ls will list the contents of the directory recusively, otherwise it will give you details of the file.

To do what you want you will need to do

ls -lR | grep filename

Or use find as you say

Upvotes: 1

Related Questions