- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Verify if [ -f file_mask*] for group of files
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-01-2010 01:31 PM
тАО02-01-2010 01:31 PM
How can I check if any of files returned at all, I tried and found that if [-f ..] works only for single file.
I'm thinking to > all output to some tmp.file and then check its size, but probably there is a better way.
Txa
all
v
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-01-2010 03:37 PM
тАО02-01-2010 03:37 PM
Solutionexample:
bash$ ls -1 cxx
a.cpp
a.h
b.cpp
files=` ls cxx/*.cpp 2> /dev/null `
bash$ if [ -n "$files" ] ; then echo 'FILES' ; else echo '(none)' ; fi
FILES
bash$ files=` ls cxx/*.xyz 2> /dev/null `
bash$ if [ -n "$files" ] ; then echo 'FILES' ; else echo '(none)' ; fi
(none)
"find" might be useful, too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-01-2010 06:26 PM
тАО02-01-2010 06:26 PM
Re: Verify if [ -f file_mask*] for group of files
filecount=`ls -1 mask* | wc -l`
then test the returned count. Tweak as necessary if dot files are involved.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-02-2010 12:49 AM
тАО02-02-2010 12:49 AM
Re: Verify if [ -f file_mask*] for group of files
ls /dir_name/file_mask* >/dev/null ; echo $?
You will only get a 0 return code if "ls" lists any files. So put this in a script and you could have:
if [ `ls /dir_name/file_mask* >/dev/null ; echo $?` = 0 ]
then
echo "We have files!!"
else
echo "NO FILES FOUND!!!"
fi
Hope that helps.
Keith
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-02-2010 12:52 AM
тАО02-02-2010 12:52 AM
Re: Verify if [ -f file_mask*] for group of files
... >/dev/null 2>&1 ; echo $? ...
Keith
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-02-2010 07:22 AM
тАО02-02-2010 07:22 AM
Re: Verify if [ -f file_mask*] for group of files
Good point.
> if [ `ls /dir_name/file_mask* >/dev/null ; echo $?` = 0 ]
But there's no need to drag in "[" ("test"),
if the command's exit status is the
criterion:
if ls /dir_name/file_mask* > /dev/null 2>&1
For example:
bash$ if ls cxx/*.cpp > /dev/null 2>&1 ; then echo 'FILES' ; else echo '(none)' ; fi
FILES
bash$ if ls cxx/*.xyz > /dev/null 2>&1 ; then echo 'FILES' ; else echo '(none)' ; fi
(none)
> As usual, many things are possible.
I stand by that.