Find git repository on macOS - bash

I would like to find the location of a Git repository I made on my mac. Is there a way to find, for exemple, albatrocity/git-version-control.markdown on macOS using the Terminal? I installed everything with default parameters. I guess it must be in the User directory but I don't find anything related to GitHub there.
When I find it, I would like to completely remove it to maker a "proper" install.
EDIT: sudo find / -name "parsing.py" -print
I used a file that I know the folder contained when Terminal showed me nothing with sudo find / -wholename "*albatrocity/git-version-control.markdown"

You can use find's -wholename option to find a file based on its name and folder:
find <directory> -wholename "*albatrocity/git-version-control.markdown"
Example, if you want to search in the /Users/ directory:
find /Users/ -wholename "*albatrocity/git-version-control.markdown"

If you have locate on mac, and a regularly running updatedb, locate might be much faster:
locate albatrocity | grep git-version-control.markdown
It uses a hashtable to fast access filenames, but can be out of date, if the database isn't updated regularly or the file is too young (typically less than one day old).
If this is without success, then I would go for a full search with find, but maybe restrict it to a possible, narrowed path.

Related

using find utility to look for all .git/config files under a certain directory

I have a certain github repo that I used to test out netlify and vuepress. I somewhat lost track of where it is on the file system, so I was planning to use mdfind (I am on mac) or find to locate all the .git/config files and then grep for my github url.
But it seems surprisingly hard to convince find to look for config under the hidden .git directories.
I did find How do I search all hidden files that are in hidden folders using Terminal? and looking at it, it looks like the following would work:
find . -name '.*' \( -type d -exec find {} \; -prune -o -print \) | egrep '/.git/config'
but given that config is a highly specific file for git, I was hoping that there is a better suited find command that will do the trick. I have already given up on mdfind as it the linked question's accepted answer is skeptical about getting it to reliably find hidden files.
Note: not looking for answers based on the locate utility, or some GUI tool, this is strictly about getting find to do the work.
Use -path.
find . -path '*/.git/config'

macOS find command behaving strangely

Example of command as used in bash script:
find '/Files' -type d -name temp* -depth -delete -print
This command should delete all folders, whose names start with "temp" in '/Files' folder and its subfolders ("temp0", "temp1", "temp2" etc.).
Script is working as expected, folders are found and properly deleted.
But sometimes, for some users, on some computers etc. script is not working as expected, despite the fact that folders & files are exactly the same.
Find command fails like this:
find /Files -type d -name tempta temptal -depth -delete -print
find: temptal: unknown primary or operator
I can't find out where "tempta" and "temptal" are coming - i don't have files with that names anywhere in the folder. Temp* folders are present, but not deleted because of this error.
The only thing which might be connected, are two files named "AbcInstall.sh" and "AbcInstall.log" in "AbcTemp" subfolder. So we have "ta" and "tal" plus "Temp". These are elements which reminds on "tempta" and "temptal", but they make no real sense - it could be a coincidence.
How can "find" result resolve into something like this !?!
Sorry for the lack of better explanation - this problem is really weird. The problem is that i can't replicate this issue on my computer so all i can do is experimenting (so far without success).
Any hints or ideas are greatly appreciated.
Thx!

"find / d" without listing all directories

I just tried to use find / d <directory> in our university server to locate a package that I want to use, and it ended up listing all of the directories in the entire server, from the most basal through all of the open directories of everybody, etc. as it searched. Is there any way to search for directories without the "verbose" mode of thousands upon thousands of directories popping up in my terminal?
To search the entire filesystem for a directory named mydirectory, use:
find / -type d -name 'mydirectory'
That is the slow way, though. On a well-configured Unix system, there will generally be a locate command installed. locate does not have all the fancy features of find but, because it works from a database, it will be much faster. To find, for example, all files in any directory called mydirectory, try:
locate /mydirectory/
Usually, locate's database is updated once a day. So, if the files or directories you are looking for were installed today, you may need to use find.

Script to find files in subdirectories

I need a script that will find and get me all files in all subdirectories (and leave them in the folder structure as they are now). I know how to find and print that files:
find . -name "something.extension"
The point is, in those directories are lots files that was used before, but I don't want to get those, so the script should only find me files that matches some kind of path pattern which is:
xxx/trunk/xxx/src/main/resources
xxx is different everytime, and after resources there are still some folders that directories are different based on xxx.
Every top xxx folder contains folder named 'tags' (the same level as trunk) that stores previous releases of module (and every release has files that name I am looking for, but I don't want outdated files).
So I want to find all that files in subdirectories of that path pattern that I specified and copy to new location but leave folder structure as it is right now.
I am using Windows and cygwin.
Update
I combined answer commands that 'that other guy' posted below, and it works. Just to be clear I have something like this:
find */trunk/*/src/main/resources -name "something.extension" -exec mkdir -p /absolute/target/path/{} \; -exec cp {} /absolute/target/path/{} \;
Thanks.
Instead of searching under the entire current directory (.), just search under the directories you care about:
find */trunk/*/src/main/resources -name "something.extension"

Mac OS X command or script to zip all subfolders with a particular name

I have a folder containing many files and subfolders multiple levels deep. I'm looking for a command or script that will zip any subfolder called "fonts", resulting in a fonts.zip file at the same level as the fonts folder.
The fonts folders should remain after creation of their zip files (no delete).
If there is a fonts folder inside another fonts folder (unlikely case), only the top-level fonts folder should result in a fonts.zip file (ideal, but not mandatory).
If there is already a fonts.zip file at the same level as the fonts folder, it should be replaced.
I'll admit, I'm a Mac newbie. Hopefully there can be a simple terminal command to accomplish this. But I'm open to other ideas how to accomplish this.
Thanks,
-Matt
Using Kevin Grant's suggestion as a starting point, I was able to put together a terminal command that works the way I needed:
find . -type d -iname '*fonts' -execdir ditto -c -k -X --rsrc {} fonts.zip \;
I referred to the man pages for the find and ditto commands and their switches. I chose to use ditto over zip because it is supposed to be more compatible with HFS and resource forks under Mac OS X. Next I'll find out if StuffIt has a command line tool. If so, I'll use it instead of ditto.
This was also helpful.

Resources