Shell Programming and Scripting

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Find a file

👤 Login to reply

    #1  
Old 05-31-2018
sbrady sbrady is offline
Registered User
 
Join Date: Sep 2015
Last Activity: 1 June 2018, 12:04 PM EDT
Location: Virginia Beach
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #2  
Old 05-31-2018
wbport wbport is offline
Registered User
 
Join Date: Sep 2013
Last Activity: 19 July 2018, 6:21 PM EDT
Location: Mississippi
Posts: 152
Thanks: 38
Thanked 22 Times in 22 Posts
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
Sponsored Links
    #3  
Old 05-31-2018
Peasant's Unix or Linux Image
Peasant Peasant is offline Forum Advisor  
Registered User
 
Join Date: Mar 2011
Last Activity: 21 July 2018, 10:28 AM EDT
Posts: 1,197
Thanks: 34
Thanked 370 Times in 318 Posts
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
MadeInGermany MadeInGermany is offline Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 21 July 2018, 6:48 PM EDT
Location: Simplicity
Posts: 4,156
Thanks: 365
Thanked 1,419 Times in 1,275 Posts
Quote:
Originally Posted by wbport View Post
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*'

The Following User Says Thank You to MadeInGermany For This Useful Post:
rbatte1 (06-01-2018)
Sponsored Links
    #5  
Old 06-01-2018
sbrady sbrady is offline
Registered User
 
Join Date: Sep 2015
Last Activity: 1 June 2018, 12:04 PM EDT
Location: Virginia Beach
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
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:
Find a file Please use CODE tags as required by forum rules!

Last edited by RudiC; 06-01-2018 at 12:10 PM.. Reason: Added CODE tags.
Sponsored Links
    #6  
Old 06-01-2018
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 21 July 2018, 12:24 PM EDT
Location: Aachen, Germany
Posts: 13,082
Thanks: 452
Thanked 4,017 Times in 3,693 Posts
find will search the entire directory tree under the given start directory and descend into each and every subdir unless told otherwise.
Sponsored Links
👤 Login to reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to find a file with a specific pattern for current sysdate & upon find email the details? PreetArul Shell Programming and Scripting 4 10-03-2013 08:46 AM
wanted to find both link file and ordinary file using single find command nikhil jain Shell Programming and Scripting 2 03-20-2012 10:30 AM
How to use grep & find command to find references to a particular file Gangam Shell Programming and Scripting 2 09-22-2011 03:52 AM
Simplified find command to find multiple file types vickramshetty Linux 2 05-28-2010 01:28 PM



All times are GMT -4. The time now is 07:22 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?