Globbing in ls...
Hello
I'm using CentOS 7. Following is the directory listing: Code:
[root@c72 /etc/systemd/system]# ls So I issued the command ls *target*, but its not working. Code:
[root@c72 /etc/systemd/system]# ls *target* Thanks |
Quote:
Code:
find . -maxdepth 1 -type f -print0 | xargs -0r ls | grep target" Code:
ls -p | grep -v / | grep target |
I would have gone with find also:
Code:
find . -maxdepth 1 -type f -name '*target*' |
@TB0ne and @grail
Unfortunately none of the commands worked. Code:
find . -maxdepth 1 -type f -print0 | xargs -0r ls | grep target = No result. Quote:
Thanks anyway. |
Quote:
Quote:
|
Quote:
Code:
[root@c72 /etc/systemd/system]# ls -l |
"next time" try
Code:
type ls |
Quote:
Code:
[root@c72 /etc/systemd/system]# type ls |
Quote:
|
Quote:
Cheers. |
Then the only problem was that ls prints directory contents rather than directory names for matches. If you only want the names, add the "-d" flag. From "man ls":
Code:
-d, --directory |
Quote:
Code:
# mkdir linuxkernel CentosLinuxOS TheLinux somefolder1 somefolder2 somefolder3 Thanks ;) |
So you wanted a case insensitive search? I didn't see you mention anything about case earlier, and indeed none of your examples had any capital letters in the word "target", so it wouldn't have mattered anyway, but...
To do that in bash you would need to use "shopt -s nocaseglob". A quick google search finds this handy little function you can put in your startup scripts: Code:
$ function i () { |
Quote:
I wont bother you anymore. Thanks for your patience. You were very helpful. :) |
All times are GMT -5. The time now is 08:10 AM. |