Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Checking existence of file using file pattern

Shell Programming and Scripting


Closed Linux or Unix Question    
 
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: 11 May 2015, 7:29 AM EDT
Location: Innsbruck, Austria
Posts: 2,154
Thanks: 12
Thanked 49 Times in 46 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 Linux or Unix Question

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 02:41 PM
checking the file existence using ssh ramesh12621 Shell Programming and Scripting 6 03-07-2011 09:13 AM
Multiple file existence and checking file size lathish Shell Programming and Scripting 2 06-29-2008 12:03 PM
Checking the existence of a file.. igandu Shell Programming and Scripting 7 06-13-2007 03:47 AM
checking file existence DILEEP410 Shell Programming and Scripting 3 01-24-2007 11:43 AM



All times are GMT -4. The time now is 04:00 PM.