Find files with the same name under a directory using ls
I want to list all suhosin.ini files under /etc/php5/ directory. The thing is that the 3 of them are one level deeper in the directory tree. I want to combine these two to one command
Code:
# ls /etc/php5/*/*/suhosin.ini Code:
# ls /etc/php5/*/suhosin.ini Code:
/etc/php5/apache2/conf.d/suhosin.ini |
Hi and welcome to LinuxQuestions!
Why don't you try find instead of struggling with ls? Code:
find /etc/php5 -name suhosin.ini |
Because i get only the first one it finds:
Code:
# find /etc/php5 -name suhosin.ini |
Really strange! Please, can you post the output of the following?
Code:
ls -l /etc/php5/apache2/conf.d/suhosin.ini /etc/php5/cgi/conf.d/suhosin.ini /etc/php5/cli/conf.d/suhosin.ini /etc/php5/conf.d/suhosin.ini |
Here it is:
Code:
root@vps1:~# ls -l /etc/php5/apache2/conf.d/suhosin.ini /etc/php5/cgi/conf.d/suhosin.ini /etc/php5/cli/conf.d/suhosin.ini /etc/php5/conf.d/suhosin.ini |
Nothing strange. What if you do the following?
Code:
find /etc/php5 -mindepth 3 -name suhosin.ini |
i thought about it but strangely for mindepth>2 i get nothing!
Code:
root@vps1:~# find /etc/php5 -mindepth 1 -name suhosin.ini |
I think i fount out why this is happening.
Code:
root@vps1:~# ls /etc/php5/ -Rl Sorry for the trouble... |
This puzzles me! There are no hard or symbolic links and they all seem regular and existing files. Which version of find (coreutils) is this and which system are you running on?
In the meanwhile, to answer to the last part of your original post, you can get the desired result by running Code:
ls -R /etc/php5/ | awk '/^suhosin.ini$/{sub(/:/,"/",dir);print dir $1}{dir=$1}' |
Well done! I was focused on the files and didn't thnk about the containers as symbolic links. So the command
Code:
find -L /etc/php5 -name suhosin.ini |
I forgot to post the result.
Code:
root@vps1:~# find -L /etc/php5 -name suhosin.ini |
You're welcome! :)
|
But did you notice that the symlinks are all "../conf.d"?
This means that all the links point back to the same directory, and so there's only a single suhosin.ini file. It's just available through multiple paths. Of course, if what you want is a list of all the paths, then great! Speaking of which, with bash's new globstar feature (v.4+), you should be able to do this with a simple globbing pattern. I just mocked up the above directory tree and ran a test: Code:
$ shopt -s globstar |
All times are GMT -5. The time now is 12:27 PM. |