- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Command to test if file exists
Operating System - HP-UX
1821831
Members
3513
Online
109638
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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
тАО10-05-2001 03:54 PM
тАО10-05-2001 03:54 PM
Command to test if file exists
I know this is a really dumb question, but I have completely forgotten the if - then test to determine if a file exists. I know it is simple, but I can't remember it or find it anywhere!
HELP!
Thanks,
Mike
HELP!
Thanks,
Mike
"If we treated each person we met as if they were carrying an unspeakable burden, we might almost treat each other as we should." Dale Carnegie
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-05-2001 04:04 PM
тАО10-05-2001 04:04 PM
Re: Command to test if file exists
Hi Mike:
Slipped a groove, huh?
if [ -r myfile -a -f myfile ]
then
echo "myfile is readable and is a reguler file"
fi
Simply man test for details.
Slipped a groove, huh?
if [ -r myfile -a -f myfile ]
then
echo "myfile is readable and is a reguler file"
fi
Simply man test for details.
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-05-2001 04:49 PM
тАО10-05-2001 04:49 PM
Re: Command to test if file exists
Mike,
Simple.
if [ -f /wherever/your_file ]
then
echo "your_file is there"
fi
There are other switches like -x, -r etc., for executable, readable etc.,
-Sri
Simple.
if [ -f /wherever/your_file ]
then
echo "your_file is there"
fi
There are other switches like -x, -r etc., for executable, readable etc.,
-Sri
You may be disappointed if you fail, but you are doomed if you don't try
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-05-2001 06:53 PM
тАО10-05-2001 06:53 PM
Re: Command to test if file exists
Hi Mike:
I don't think you'v "slipped a goove".
To me the 'test' command isnt't necessarily the obvious place to find what you seek. That aside, take a look at '-r' for testing if a file is (r)eadable and therefore by infererence that it exists. Contrast this with the need to determine that it is a regular file instead of a special file (like a device file, or a socket) [-f]; or that the file has a size greater than zero bytes [-s]; or an important, useful test like [-t] to determine whether or not the file is associated with a terminal (ever so useful with scipts when you want to differentiate between a 'cron' initiated process and one started from a shell's command line!
Take a look at these, and other options, in the 'test' command.
Maybe this thread will help you remember ;-)
Regards!
...JRF...
I don't think you'v "slipped a goove".
To me the 'test' command isnt't necessarily the obvious place to find what you seek. That aside, take a look at '-r' for testing if a file is (r)eadable and therefore by infererence that it exists. Contrast this with the need to determine that it is a regular file instead of a special file (like a device file, or a socket) [-f]; or that the file has a size greater than zero bytes [-s]; or an important, useful test like [-t] to determine whether or not the file is associated with a terminal (ever so useful with scipts when you want to differentiate between a 'cron' initiated process and one started from a shell's command line!
Take a look at these, and other options, in the 'test' command.
Maybe this thread will help you remember ;-)
Regards!
...JRF...
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP