testing if a file is present

Jon H. LaBadie jon at jonlab.UUCP
Tue Nov 27 18:56:41 AEST 1990


> In article <ger.659126250 at prisma> 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 

A number of poster have responded to Ger's posting by suggesting the
-f option of test (builtin or separate executable).  Most claimed this
option tests if the file exists and suggest that the manual be read.

They should read the manual which says:

	-f file   true if file exists AND is a regular file

(emphasis mine)

I.e., the -f is a filetype/existance test.  If a directory foobar
exists, test -f foobar is false; test -d foobar is true.

There are a number of filetype/existance options to test:

	-f	regular files
	-d	directory files
	-b	block special files
	-c	character special files
	-p	named pipe files (fifo's)

and on some systems:

	-????	symbolic link files

Jon

-- 
Jon LaBadie
{att, princeton, bcr, attmail!auxnj}!jonlab!jon



More information about the Comp.unix.shell mailing list