- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Test file size
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
Forums
Discussions
Discussions
Discussions
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
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
12-20-2001 07:18 AM
12-20-2001 07:18 AM
I would like to test a file size. If a file is equal to zero or 1 test would fail, and if a file was greater than 1 test would pass. I know there was be an easy way to do this. Thanks everyone for your help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2001 07:21 AM
12-20-2001 07:21 AM
Re: Test file size
NUM=`ll filename | awk '{print $7}'`
if [ $NUM -gt 0 ]
then
exec command1
else
exec command2
fi
MC,
C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2001 07:22 AM
12-20-2001 07:22 AM
Re: Test file size
NUM=`ll filename | awk '{print $7}'`
if [ $NUM -ge 1 ]
then
exec command1
else
exec command2
fi
Notice the ge and 1, I did not read it right the first time...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2001 07:24 AM
12-20-2001 07:24 AM
SolutionNUM=`ll filename | awk '{print $7}'`
if [ $NUM -le 1 ]
then
exec command1
else
exec command2
fi
My short term memory is shot today.
HH,
C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2001 07:26 AM
12-20-2001 07:26 AM
Re: Test file size
You can use find -size n[c] try to read the man page of find.
Regards,
Justo.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2001 07:38 AM
12-20-2001 07:38 AM
Re: Test file size
The routine looks like this:
#!/bin/sh
NUM=`ls -l filename | awk '{print $5}'`
if [ "$NUM" -gt 1 ]
then
echo command1
else
echo command2
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2001 10:43 AM
12-21-2001 10:43 AM
Re: Test file size
SIZE=`ls -l $YOURFILE|awk '{ print $5 }'`
if test "$SIZE" -gt "1"
then
do something
else
do something else
fi
This will fail if the file doesn't exist, however. To test if the file exists AND THEN
test to see if its size is larger than 1 byte:
if test -f YOURFILE
then
insert the above script
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2001 01:29 PM
12-21-2001 01:29 PM
Re: Test file size
You guys are doing it the hard way.
How about
if [ -s myfile ]
then
echo "File exists and has a size greater 0"
else
echo "File does not exist"
fi
Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2001 04:10 PM
12-21-2001 04:10 PM
Re: Test file size
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2001 07:00 AM
12-22-2001 07:00 AM
Re: Test file size
Remember the question is whether the file size is greater than 1. Thus, [ -s myfile ] is inadequate as it tests for greater than 0.
:)
Darrell