tags:

views:

40

answers:

2

Hi

I am trying to use: ls -la *randomString* in my shell script to list out all the files and directories that contain a substring: "randomString"

everything works fine except when it encounter a directories that matches the substring, when it does it will give me something like this: (lets say the directory name was "TTrandomStringTT")

-rw-r----- 1 myName none 7 Jan 17 17:57 .YrandomStringY.txt

TTrandomStringTT: total 16

drwxr-s--x 2 myName none 4096 Jan 17 18:00 .

drwxr-s--x 3 myName none 4096 Jan 17 19:00 ..

what I want it to do is list

drwxr-s--x 2 hctsui none 4096 Jan 17 18:19 TTfrandomStringTT

just as a normal ls -la would do

I am really new to shell so I really need some help thankyou so much for helping me

+2  A: 

If your glob matches a directory name, it will list the contents of the directory. If you don't want that to happen, do ls -lad *randomString*

Paul Tomblin
thankyou so much!!! it worked
Shellscriptbeginner
@Shellscriptbeginner, so **accept** this answer already -- that's what the checkmark icon under the number and up/down arrow icons for this answer is **for**, and it's a crucial part of SO's etiquette!
Alex Martelli
oh sorry I didn't know that, I just joined. I thought the arrow up was the one that does that, but when I click it it say i dont have enough rep
Shellscriptbeginner
@Shellscriptbeginner - that's ok, we're all here to learn. I thought you already knew because you'd accepted the answer to the other question you'd asked.
Paul Tomblin
lol o i did? I probably clicked on that accidentally
Shellscriptbeginner
+2  A: 

another way you can use is find, which recursively search for you.

find . -iname "*randomstring*" -ls
ghostdog74