문제

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

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top