1

I tried to search for a folder in its parent folders instead of its child sub-folders (usually any search bash command will do). I need to know whether any reverse alternative for any search commands actually exists.

  • What do you mean by "using find . -iname in reverse order"? I don't understand, either, what a "reverse alternative" would be. Could you give some examples? – Jeff Schaller Oct 24 '18 at 10:08
  • 1
    What is expected behavior of that ? If you can search through all parent folders you can search from / as well. – mrc02_kr Oct 24 '18 at 10:09
  • @JeffSchaller Sorry, i would have referred to it better. All i need to know, is there any possibility to search for a folder or file or any content in parent directories rather than searching it in its child sub directories. – Prabhu Rk Oct 24 '18 at 10:48

1 Answers1

0

If you want to search in a parent directory you should use "../" as the path. And then exclude the folder you are in.

Maybe something linke this? (Assume that you are in "currentfolder" when running the command.

find ../ -iname "file" -not -path "../currentfolder/*"

This will search the parent folder and subfolders in those. I kinda think the best way is to seach from the top, and im not sure there are other ways.

  • And of course use "-type d" to find folders and not files. – Dennis Wiencken Oct 24 '18 at 10:27
  • For example, if I wanna search for .hg or .git folder (if it is a cloned repository) and I don't have any clear idea about which folder under those folders reside. Then how do I know how deep I have to go backwards?! – Prabhu Rk Oct 24 '18 at 10:39
  • Why not search from the top? Like searching from "/" or "/var/www/". You must have some idea what top folder the folders are located in. – Dennis Wiencken Oct 24 '18 at 11:23