开发者

shell script ls globbing question

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 myNa开发者_Go百科me 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


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*


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜