Shell Script for searching Makefile recursively in directories - shell

I need to build a shell script on debian based OS to recursively browse and identify which Folders have Makefile present. If present then build the package. If not present then just list those folders. The catch here as shown below is I need to browse only one folder below the parent folder (ABC) and check if makefile is present under Folder1, Folder 2...etc and not to go into the sub directories of Folder1 (not to look for Makefile under folders Folder1.1, Folder 1.2, Folder2.1 etc). Looking for some tips how to loop only one level and then exit back to folder ABC and start the search.
ABC---
|---Folder1
| |-------Makefile
|-------Folder1.1
|-------Folder1.2
|---Folder2
| |-------Somefile
|-------Folder2.1
|-------Folder2.2
|---FolderN
| |-------Makefile
|-------FolderN.1
|-------FolderN.2

As answered by Karthikraj in above comments. This helped
find . -maxdepth 2 -type f -iname 'makefile'

Related

Find Count of .XML Files in Directory / Sub-Directory

I have a directory with millions of sub directories with millions of sub directories and each directory may contain .XML files or another sub directory ... what I need is to count the number of .XML files in the parent directory in UNIX ...
I've tried a lot of this but ended up with listing them not counting them - Any ideas ??
I'm guessing you're looking for the number of xml files on the children directories, not parent. If so, this should do the trick:
find . -type f -name \*.xml | wc -l
Make sure you're on the top level directory from where you want to search. It will display all files named *.xml and count the returned lines.

Find files with ".logic" in name, but exclude files inside "Project File Backups" subdirectories

I need to identify all of the files in my directory which have ".logic" in name but exclude files of subdirectories called "Project File Backups". You can see an example of one of my projects, which has a series of backup files (file_name.xx.logic). I only want to see the project file itself, here it is called KillBill.logic.
Here is a project structure for reference
Audio Files
KillBill.logic
Project File Backups
KillBill.00.logic
KillBill.01.logic
KillBill.02.logic
KillBill.03.logic
KillBill.04.logic
Sampler Instruments
Samples
I have cd'd to the correct directory, and run the following command to show ALL of the files with ".logic" in the name:
find . -name "*.logic"
I have tried to whittle the results down as per the stated requirement, without success. My attempts so far have been
find . -name "*.logic" -not -path "*Backups*"
find . -name "*.logic"| awk '!*Backups*' (there's a problem with the awk statement)
find . -name "*.logic" ! -name "*Backups*" ( I suspect that this doesn't work because the name of the file itself doesn't include "Backup" in it
I could find . -name "*.logic" ! -name "*.*.logic" to just exclude any .logic file which appears to have version information in its name, but I cannot guarantee that valid files do not have a period in the name, hence my desire to exclude Project File Backups directories.
What invocation of find should I use to list the project files and exclude the backup files which exist in each project's "Project File Backups? I'd prefer to use find and not a combination of other commands.
rename all files with .logic in "Project File Backups" into .logicpfb and rename them all back when done
I couldn't find a way to do it using only find, but the following worked well
find . -name "*.logic" | grep -v "Project File Backup" -c

How to find a file in a subdirectory where only the top level and a mid level directory are known

I'm trying to use bash to find a target file in a deep directory hierarchy whose top level directories and a mid-level directory are known but whose remaining directories may be of any arbitrary structure:
/A/B/[unknown]/[unknown]/.../C1/[unknown]/[unknown]/.../TargetFile
/A/B/[unknown]/[unknown]/.../C2/[unknown]/[unknown]/.../TargetFile
/A/B/[unknown]/[unknown]/.../C3/[unknown]/[unknown]/.../TargetFile
Let's say that I would like the path to TargetFile in the directory tree that includes directory C2. I made some crude but obviously flawed attempts with the find command, such as:
find '/A/B' -path '/C2/*' -name 'TargetFile'
Is there a way to accomplish this with find or with some other approach? (I am using the Mac OS version of the find command.)
With this example command you start a search from /home, and look for TargetFile contained in any directory named C2:
find /home -path '*/C2/*' -name 'TargetFile'

script to find /rsync - a specific files between 2 dirs with identical internal folder structure

I have two dirs which contain all the files for a mobile phone system/rom. I'll call them /rom1 and /rom2
Both rom1 & rom2 have identical directory structure within.
The full file path to each is similar to
User/me/development/rom1/system
User/me/development /rom2/system
I want to copy / rsync -av all the folders and files with camera. * from rom1/system/ to its equivalent folder in rom2/system/
ie: generate a scrip that does... rsync - av User/me/development/rom1/system/app/camera.apk User/me/development/rom2/system/app/
In case it's useful I have already generated a list of all the folders and files including their file path (starting at /system) I want copied over. It looks like :
system/app/camera.apk system/bin/lib/camera.so system/vendor/camera/ system/very-long-list /etc etc...
I know how to use Individual Unix tools but I'm having trouble putting it all together to do what I want in a bash script.
this is a non functional example that will give you an idea of what Im trying to do.
DIR1=User/me/development/rom1/
OLDPATH=$(find . -name '*camera*.*' -exec $pwd { } \;) | NEWPATH=$(sed -s /rom1/rom2/ $OLDPATH) | for SELF in { } ; do
rsync --dry-run -Rav $DIR1$SELF $NEWPATH

Shell script to write folder tree structure to file

I need a shell script that writes the tree structure (including all data in the folders) from a specific folder to a text/dat file.
So far I got this:
find . -type f|sed 's_\.\/__' > PATH/Input.dat
I dont want a "/" as the first char of the path.
This script works fine, but it returns ALL folder structures. I need something that returns only structures from a specific folder, like "Sales".
I need something that returns only structures from a specific folder,
like "Sales".
Specify the desired folder name. Say:
find Sales -type f | sed 's_\.\/__'
^^^^^
Saying find . ... would search in . (i.e. the current directory and subdirectories).
If you need to search more folders, say Purchase, specify those too:
find Sales Purchase -type f | sed 's_\.\/__'

Resources