linux - find using regexp and echo matches
2014-07
I have about 50 users in /home/ directory and I have cloned a git repository to everyone:
Executed at /home/ as root user:
find . -maxdepth 1 -type d ! -name . -prune -exec git clone /shared/repos/project_xpto.git {}/www/xpto/ \;
Now I need to set owners to these cloned repositories.
I want to execute chown user_folder_name:development -R ./user/www/xpto/ for each cloned repo.
Then I started with:
find . -maxdepth 1 -regextype sed -regex "./\([A-Za-z0-9-_]\).*" -type d -exec echo {}/ \;
And I want to envolve to:
find . -maxdepth 1 -regextype sed -regex "./\([A-Za-z0-9-_]\).*" -type d -exec chown ${expr1}:development {}/www/xpto/ -R
I know ${expr1} does not exists. I just wanna know how to return my first matched regexp pattern, then I will get just username, without dots and slashes, from each folder to set owner.
I have a file with joker character patterns:
./include/*
./src/*
etc.
From the current directory I would like to recursively get the list of files that do not match these patterns.
find . -type f \! \( -path '*/include/*' -o -path '*/src/*' \)
Breakdown:
\!
is negating the group\( ... \)
is how to do groups of conditions forfind
-o
ORs conditions- Everything else should be self-explanatory.
If you have a new enough version of find
, you could enhance it with:
find . -type f -regextype posix-egrep -regex \! -path '.*/(include|src)/.*'
First approach, but not using a list of files, others feel free to improve on that:
find . -type f -print | grep -v '.\/src\/*'