Within a dir, I am trying to find anything that matches config/db, where db could be a file or dir.
I tried:
find /search/root/dir -wholename 'config/common'
but that didn't work - result set was empty but I know that path exists, anybody know how to find a path with slashes in it?
If you know only the partial path then -wholename, may not work.
You can use..
find . -path "/search/root/dir/config/*"
find . -path "*/search/root/dir/config/"
Related
I have a file structure as following:
/home/myhome/me/staging/15/1234/my_stats/
/home/myhome/me/staging/16/5678/my_stats/
/home/myhome/me/staging/17/7890/my_stats/
/home/myhome/me/staging/18/3456/my_stats/
I need to travel to the dir "my_stats" and execute query to find files in my cmd. There are multiple dirs in "staging" and I need to go into every one of them and check if 'my_stats' dir exists. If it exists, then I need to run a cmd query in "my_stats" dir.
The dir structure will always be in the following format:
/home/myhome/me/staging/<2 digit name>/<4 digit name>/my_stats/
I have tried iterating through the structure using a nested for loop and checking all dirs in 'staging' which is proving to be slow. Is there a way to using the 'find' command with 'depth' to do the same?
Or can we implement this with pattern matching ?
Appreciate the help. Thanks!
found the answer!
we can use * for it.
/home/myhome/me/staging/*/**/my_stats/*
Will try to find a better solution which can maybe use len of dir to better differentiate it
Try this one
find . -type f -path "./[0-9][0-9]/[0-9][0-9][0-9][0-9]/my_stats/*"
can replace the . with your own path.
I could see a file is present in the location when I do ls, but when I do find on that file, it doesn't show; under what circumstance it might happen? Thanks.
[mega#bhlinapps]$ ls build_framework/scripts/CommonBuildScripts/itr_build.pl
build_framework/scripts/CommonBuildScripts/itr_build.pl
[mega#bhlinapps]$ find . -name itr_build.pl
[mega#bhlinapps]$
fly#fly-desktop:~/Documents$ ls py/faces/face_landmarks.csv
py/faces/face_landmarks.csv
fly#fly-desktop:~/Documents$ find . -name faces_landmarks.csv
fly#fly-desktop:~/Documents$
I did achieve your result.
i wrote a function named find in the terminal
fly#fly-desktop:~/Documents$ find(){ a=2
> }
then find will not call the as you expect. Probably you wrote a function called find in your ~/.bashrc file which has the same name as find
I'm sure I had a working oneliner that allowed me to search a directory (or .) for files containing names matching names in a txt file and copying these to a new directory.
Somehow I cannot get it to work - any help please.
Sorry if this is a duplicate - I have really searched for an answer (here and elsewhere), but cannot find a solution.
foo/movehere/sample.txt file:
141516
141619
Files I want to find and move i.e.:
foo/folder/folder2/141516_S2_R1.fastq.gz
foo/folder/folder2/141516_S2_R1.fastq.gz
Where I want to move them:
foo/movehere/
my current (nonfunctioning) oneliner:
while read -r FILE; do find . -name "$FILE*.fastq.gz" -type f -exec cp {} /foo/movehere/ \;;done </foo/movehere/sample.txt
There are some errors in the oneliner. It still does not work.
you can use eval in your code
SEARCH="-name '$FILE*.fastq.gz'"
eval "find . $SEARCH -type f exec cp '{}' /foo/movehere/ \";
security note : do not put user supplied data into eval.
Not sure if I should delete the post - but I'll leave my solution here if anyone else encounter the exact same problem.
Still not 100% sure I understand why it failed, but I got the oneliner working by copying all the sample names from the txt to a unedited file with no suffix.
I guess some (hidden) "\r" editing in the txt file messed up the "$FILE" so that it searched for something like this:
151617*fastq.gz\r
Perhaps someone with a better understanding of terminal scripts may confirm this.
EDIT 190128: happened across my old question, and just in case anyone struggle with something similar, make sure you have UNIX or similar line shifts, my txt files had weird window line shifts.
So I have a directory that has a number of files. I'm wondering what I need to find files within that directory. My files have a naming convention and then a last name. I'd like to find by the naming convention.
/MyDir/MySubDir/2016_01_randomLastNameABC
/MyDir/MySubDir/2016_01_randomLastNameDEF
/MyDir/MySubDir/2016_01_randomLastNameGHD
/MyDir/MySubDir/2016_01_randomLastNameDGD
find "/MyDir/MySubDir/2016_01_*"
I keep getting an error that says:
"linux file names usually don't contain slashes"
It must not like the fact that I'm trying to search a directory
Try
find ./MyDir/MySubdir/ -name "2016_01_*"
find /MyDir/MySubDir -name "2016_01_*"
This will do
find /MyDir/MySubDir/ -name "2016_01_*"
test,
~$ find ./market/public/static/ -name *.js
./market/public/static/view3dview.js
./market/public/static/ng-file-upload.min.js
./market/public/static/codemirror-min.js
./market/public/static/model_upload_app.js
I am using Linux(Ubuntu), I am trying to find the files, but it is not working properly.
I have created some files in my directory structure, for example: World/India/Maharashtra/Pune/filename.xml
When I use the find command like:
find /home/lokesh/Desktop/Testing_India2/Test/World/India/Maharashtra/ -name filename*.xml -mmin -3000
It is giving the result perfectly.
But, when I am using the same command at "World" or "India" level:
find /home/lokesh/Desktop/Testing_India2/Test/World/ -name filename*.xml -mmin -3000
it does not give any result.
I have lots of directories at "India" level as well as at "Maharashtra" level and may be some directories within "Maharashtra's" inner directories. I have to find each file created in all directories.
And I have mounted all folders from different machine.(I mean some state from different and some from different machine.)
If someone knows how to solve this problem please reply me as soon as possible.
Double quote your search string and -L to make it follow symbolic links:
find -L /home/lokesh/Desktop/Testing_India2/Test/World/ -name "filename*.xml" -mmin -30000
This is something I ran into earlier today actually when using the '*' wildcard. I couldn't get it to continually traverse the subdirectories unless I escaped the * with a .
Give this a try:
find -L /home/lokesh/Desktop/Testing_India2/Test/World/ -name filename\*.xml -mmin -30000
Yes, as mentioned you have to double qoute your -name argument or use a backslash prior to the *. The reason for it not working from one directory, but working fine in other directories, is that the * character is used for filename generation by your shell. This of course happens before the find command is executed. Therefore, if you have a file that match the filename*.xml pattern in your current directory it will be substituted before find is executed, which is not what you want. On the other hand, if there is no pattern match in the current directory, the * character is passed on to the find command unmodified. By qouting you protect the string from shell filename generation.
Regards