Article View: comp.unix.shell
Article #1809Re: testing if a file is present
From: Bill Irwin
Date: Wed, 21 Nov 1990 23:02
Date: Wed, 21 Nov 1990 23:02
28 lines
1310 bytes
1310 bytes
ger@prisma.cv.ruu.nl (Ger Timmens) writes:
>Can anybody tell me how I can verify
>whether a file exists or not ?
>I want to move files and only when
>they exist ! mv "file" gives an
>error message if "file" not exists
Try this:
if [ -f file_name ]
then
mv file_name /new/destination/file_name
fi
The "-f" tests for the existence of the file. There are other options:
-x is the file executable
-r is the file readable
-s does the file have anything in it (greater than zero bytes)
There are others too. Check your manual under "sh". The options should be
listed.
--
Bill Irwin - The Westrheim Group - Vancouver, BC, Canada
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
uunet!van-bc!twg!bill (604) 431-9600 (voice) | UNIX Systems
bill@twg.bc.ca (604) 430-4329 (fax) | Integration
Technical Details
Message-ID:
<332@twg.bc.ca>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!van-bc!twg!billReferences:
<ger.659126250@prisma>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!van-bc!twg!bill From: bill@twg.bc.ca (Bill Irwin) Newsgroups: comp.unix.shell Subject: Re: testing if a file is present Message-ID: <332@twg.bc.ca> Date: 21 Nov 90 23:02:25 GMT References: <ger.659126250@prisma> Distribution: comp.unix Organization: The Westrheim Group, Vancouver, B.C., Canada Lines: 28