Unix/Linux Go Back    


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.

Checking existence of file using file pattern

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 09-30-2008
spkandy spkandy is offline
Registered User
 
Join Date: Sep 2008
Last Activity: 30 June 2010, 12:11 PM EDT
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Checking existence of file using file pattern

Hi ExpertsLinux,
I need to check the existense of file using patterns.How can i do it?
Ex:
if my current directory has a number of files of pattern (ins_*),
i need to check the existense of atleast one file.
pls reply me.
Sponsored Links
    #2  
Old Unix and Linux 09-30-2008
ShawnMilo ShawnMilo is offline
Registered User
 
Join Date: Jun 2006
Last Activity: 10 November 2009, 8:27 AM EST
Posts: 252
Thanks: 0
Thanked 1 Time in 1 Post
PHP

This seems to work for me. There may be (and probably is) a better way to do it.


Code:
 if test -n "$(ls ins_*)"; then echo "yep"; else echo "nope"; fi

Sponsored Links
    #3  
Old Unix and Linux 09-30-2008
otheus's Unix or Linux Image
otheus otheus is offline Forum Advisor  
Smartass
 
Join Date: Feb 2007
Last Activity: 6 October 2016, 6:06 AM EDT
Location: Innsbruck, Austria
Posts: 2,156
Thanks: 12
Thanked 51 Times in 48 Posts
ShawnMilo's response is pretty good, I think. Just to be sure, you might want to use:


Code:
 if test -n "`/bin/ls -1 ins_* 2>/dev/null`"; then echo "yep"; else echo "nope"; fi

Otherwise, you'll get a "file not found" error, or if your output starts with a dash, you'll have problems.
    #4  
Old Unix and Linux 10-01-2008
spkandy spkandy is offline
Registered User
 
Join Date: Sep 2008
Last Activity: 30 June 2010, 12:11 PM EDT
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks a lot ShawnMilo & Otheus...!

Linux
Thanks a lot ShawnMilo & Otheus...!
Its working fine.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Checking existence of file using awk manish007 Shell Programming and Scripting 6 01-23-2012 03:41 PM
checking the file existence using ssh ramesh12621 Shell Programming and Scripting 6 03-07-2011 10:13 AM
Multiple file existence and checking file size lathish Shell Programming and Scripting 2 06-29-2008 01:03 PM
Checking the existence of a file.. igandu Shell Programming and Scripting 7 06-13-2007 04:47 AM
checking file existence DILEEP410 Shell Programming and Scripting 3 01-24-2007 12:43 PM



All times are GMT -4. The time now is 09:25 AM.