I want to write a function that will find files in current directory I'm currently in. The thing is that if I'm in /home
, I want to find files in sys
, dev
and var
directories (which is in my home folder). But If I'm in root folder I wish them to be stripped. I tried this:
find -L . \( -path '/dev' -o -path '/var' -o -path '/sys' \) -prune \
-o -type f -print \
-o -type d -print \
-o -type l -print
But its not working. If I set a dot (.) at beginning of every path I want to exclude - it works for root folder, but also excludes such dirs in other directories, which I do not want.
Is there a way to prune by full (global) file path? I tried a -wholename
option, but It seems not work for me.
You can use
find "$PWD"
, as infind "$PWD" -path '/dev' -prune -o -print
, to search in the current directory by absolute path. Absolute path matches will then succeed.