testing if a file is present

Bill Irwin bill at twg.bc.ca
Thu Nov 22 10:02:25 AEST 1990


ger at 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 at twg.bc.ca            (604) 430-4329 (fax)   |     Integration



More information about the Comp.unix.shell mailing list