Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does file exist?

Status
Not open for further replies.

tbohon

Programmer
Apr 20, 2000
293
US
Need to be able to determine whether or not a specific file exists in a specific directory. Situation is this: if the file has already been compressed (e.g., a .Z file) then I need to use zcat ... but if it hasn't been compressed, I'll need to use cat.

Isn't there a Unix command that returns a value indicating the existence of the file?

Tnx as always in advance.

"My mind is like a steel whatchamacallit ...
 
You can use the test operator in an if statement like so:

cd (desire directory)
if [ -f filename.Z ]
then
zcat filename
else
if [ -f filename ]
then
cat filename
fi
fi
 
That simple, huh? Now I really AM embarassed ... I was headed completely the wrong direction with a much more convoluted method ... <sigh>

Actually I haven't worked with Unix scripting for several years and am real, REAL rusty. My duties at the hospital now include being system administrator for several different Unix servers so I'm fast-tracking the learning curve.

Appreciate it a great deal - have a great evening/day/week!!!

Tom

"My mind is like a steel whatchamacallit ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top