Find a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find a file
# 1  
Old 05-31-2018
Find a file

see attachment. I need to find a FOLDERS using just the first word of the folder (ie SUV28). So I need to find the SUV28 folder in "Features1/SU"

Here is something I have trying to get to work but can't. Can anyone help me make this work.

This is actually in Applescript on Mac.

Code:
set proj_code to "SUV28"
set basePosix to quoted form of (POSIX path of "Features1:SCRIPTS:SU:" & proj_code & " *")
set the_SCRIPT_folder to (do shell script "ls -d " & basePosix)
set x to the_SCRIPT_folder






Dropbox - SUV28.png
# 2  
Old 05-31-2018
This should find anything starting with what you want, but finds everything, not just folders:
Code:
find / -name 'SUV28*'

but you may have to pipe the output thru
Code:
grep "^dr"

to only get directories.


HTH
# 3  
Old 06-01-2018
Hopefully this example will shed some light to usage in your example
This is on debian, but it should work anywhere.
Code:
user@hostname:~Features1/SU$ pwd
/home/user/Features1/SU
user@hostname:~Features1/SU$ ls -lrt
total 12
drwxr-xr-x 2 user group 4096 Jun  1 04:57 'SUV25 Johnson, Ben'
drwxr-xr-x 2 user group 4096 Jun  1 04:59 'SUV563 Oort, Jan'
drwxr-xr-x 2 user group 4096 Jun  1 05:00 'SUV28 Curie, Marie and Pierre'
drwxr-xr-x 2 user group 4096 Jun  1 05:10 'SUV286 Baggins, Frodo'

# we only find directories SUV28 in above output, but any regular expression will do
user@hostname:~/posao/struk$ find /home/user/Features1/SU -type d -name "SUV28\ *" -exec ls -dl {} \; 
drwxr-xr-x 2 user group 4096 Jun  1 05:00 '/home/user/Features1/SU/SUV28 Curie, Marie and Pierre'

Hope that helps
Regards
Peasant.
# 4  
Old 06-01-2018
Quote:
Originally Posted by wbport
This should find anything starting with what you want, but finds everything, not just folders:
Code:
find / -name 'SUV28*'

but you may have to pipe the output thru
Code:
grep "^dr"

to only get directories.


HTH
That does not work.
But you can filter for directories in find
Code:
find / -type d -name 'SUV28*'

This User Gave Thanks to MadeInGermany For This Post:
# 5  
Old 06-01-2018
find command

if I use this:
Code:
find / -type d -name 'SUV28*

how does it know what folder to look in to ie "Features1/SU"
how do I tell find to look into the Features1/SU folder for the SUV28 folder.




Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 06-01-2018 at 01:10 PM.. Reason: Added CODE tags.
# 6  
Old 06-01-2018
find will search the entire directory tree under the given start directory and descend into each and every subdir unless told otherwise.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can you use find with ps or doing find excluding file in use

Hi, I am currently using the find below to remove old files. I am redirecting the listing to a file and then use a while-loop and do a rm cd ${directory} find . \( ! -name . -prune \) \( -type f -name "*.trc" -mtime +10 \) | sed 's#^./##' | sed "s#^#${directory}/#" 2>/dev/null | tee -a... (4 Replies)
Discussion started by: newbie_01
4 Replies

2. Shell Programming and Scripting

How to find a file with a specific pattern for current sysdate & upon find email the details?

I need assistance with following requirement, I am new to Unix. I want to do the following task but stuck with file creation date(sysdate) Following is the requirement I need to create a script that will read the abc/xyz/klm folder and look for *.err files for that day’s date and then send an... (4 Replies)
Discussion started by: PreetArul
4 Replies

3. Shell Programming and Scripting

wanted to find both link file and ordinary file using single find command

find . -type fl o/p is only the ordinary file. where in it wont give the link files. (2 Replies)
Discussion started by: nikhil jain
2 Replies

4. Shell Programming and Scripting

Find multiple string in one file using find command

Hi, I want find multiple string in one file using find coomand. And keeping it in one variable.grep is not working. (5 Replies)
Discussion started by: vivek1489
5 Replies

5. Shell Programming and Scripting

How to use grep & find command to find references to a particular file

Hi all , I'm new to unix I have a checked project , there exists a file called xxx.config . now my task is to find all the files in the checked out project which references to this xxx.config file. how do i use grep or find command . (2 Replies)
Discussion started by: Gangam
2 Replies

6. Linux

Simplified find command to find multiple file types

Hi, I'm using the following command to find the multiple requierd file types and its working fine find . -name "*.pl" -o -name "*.pm" -o -name "*.sql" -o -name "*.so" -o -name "*.sh" -o -name "*.java" -o -name "*.class" -o -name "*.jar" -o -name "*.gz" -o -name "*.Z" -type f Though... (2 Replies)
Discussion started by: vickramshetty
2 Replies

7. UNIX for Dummies Questions & Answers

How to find a file whick is consuming larger disk space in file system

Hello, Can anybody please tell me the command to find out the filesystem or a file which is consuming larger disk space sing i want to find out the file and want to compress it please help me out any help would be appreciated (6 Replies)
Discussion started by: lokeshpashine
6 Replies

8. UNIX for Dummies Questions & Answers

how to find a file named vijay in a directory using find command

I need to find whether there is a file named vijay is there or not in folder named "opt" .I tried "ls *|grep vijay" but it showed permission problem. so i need to use find command (6 Replies)
Discussion started by: amirthraj_12
6 Replies

9. Shell Programming and Scripting

how to find a file in UNIX without find command?

given a start directory,a filename,how to find it? (3 Replies)
Discussion started by: bluo
3 Replies
Login or Register to Ask a Question