use the "test" command with the "-f" option. It tests for the existence of a (regular) file. You could even refine your test with the "-r" option, which tests for a regular file which has read access:
Employing the logic you use it would be possible to set a flag:
Notice that i have not used a for-loop but a while-loop instead. The reason is that the commandline has a limited length (4096 characters per POSIX 1003). As the wildcards get expanded when processing the commandline it can well be that many matching files would make a string too long for the shell to digest. You would get a "line too long-error". Therefore the while-loop and a pipeline is more safe than the for-loop.
Hi,
I have a script which will check the fiel existence, the lines are as below
if !(test -d ./data) then
mkdir data
fi
In the first line error occurs as below
generatelicense.sh: syntax error at line 2: `!' unexpected
Where as this script works fine in linux OS.
How to solve... (2 Replies)
Hi,
I would like to check the existence of files (doesn;t matter the number of files) in a directory.
My file is named in the following manner (always ending with " myfile "). Can anybody give me some guidance?
EG:
abc1_myfile
sdfr_myfile
sffgd_myfile
and so on ......
My... (9 Replies)
i can able to transfer a file from build server(AIX)to webserver using ksh through ftp.my query is to check the existence of file while transfering from one server to other .i.e i need some command or script that checks the existence of file with same name in both server,within ftp syntax.
... (1 Reply)
we have tranferred an ear from local server to remote server using ftp.consider, we have an ear file named a.ear in remote server,again if we transfer the same file named a.ear from local server to remote server.we need the kshell to check the existence of the ear file in remote server,and if the... (3 Replies)
Hello
I am having a requirement like if there is no file in the directory then i need a message to pop on after the execution of the script.
My script basically does for File in `ls -t $DIRECTORY | tail -1`;
if there is no file the DIRECTORY then the script is simply exiting with out... (2 Replies)
i want to check if the file is in the directory or not, and also it should be handle error conditions, like missing files and report the error and exit.
i did something like this:
file ="hello"
if !test -e "${file}"
then echo "No such files exist!"
exit 1
else
do something.......
fi
... (1 Reply)
I am using the following command to check for files on a Unix (Solaris 9) and on Linux:
if (-r *.) then
echo " las file found"
else
echo " no las file found"
endif
If no las file is present, the "no las file found" message is displayed. If a las file is present, however, I get... (9 Replies)
Hi All.
Pls help me with the command to check existence of files (I'll mention name of the file as regex) and proceed with my further processing if atleast one of them exists
in detail,
I've a dir /tmp/TURP, which may or may not have files named with "exter*.txt"
I need to check and... (2 Replies)
I need to check for the existence of a file *.log in a specific directory using a perl script.
Presently am not in that particular directory.
So i am using chdir ("/path/to/my/file)
And then i am using the -e in an if statement to check if it exists.
if (-e $File) {......}
$File contains the... (1 Reply)
hi
i wanted to check if the file exist or not(multiple files)
DIRE=/home/V478
if ;
then
echo "file present"
else
echo "file not present"
fi
But i am getting the error as
: [: unexpected operator/operand (3 Replies)
Discussion started by: ATWC
3 Replies
LEARN ABOUT DEBIAN
cg
CG(1)CG(1)NAME
cg - Recursively grep for a pattern and store it.
SYNOPSIS
cg [ -l ] | [ [ -i ] pattern [ files ] ]
DESCRIPTION
cg does a search though text files (usually source code) recursively for a pattern, storing matches and displaying the output in a human-
readable fashion. It is intended to give some of the functionaly of AT&T's cscope(1) tool, with the advantages of simplicity and not being
language-specific. The script will colorize output if configured as such.
It is typically run with a Perl regular expression to search for. The search can be made case insensitive by using the -i option. A list
of files may also be specified with an additional argument after the pattern. Put the files pattern in quotes to make it be matched by
Perl rather than by the shell. Running the script with no arguments will recall the results of the previous search. After the search,
entries found can be edited using the vg(1) script. The -l option shows the last log made.
SOME EXAMPLES
cg - alone recalls the previous search results.
cg -i pattern - search the default list of files for all files matching the pattern (and case-insensitively).
cg pattern '*.c' - search recursively for pattern in all *.c files. This automatically converts '*' to '.*' and '.' to '.' for you and
does a Perl pattern match on all files in the tree.
cg pattern *.c - search through the shell-expanded list of *.c files, so not done recursively (in other words, only the files your shell
pass to the script as arguments).
cg -l - show the last log made.
COMMAND-LINE OPTIONS-i Do a case-insensitive search.
-l Show the last log made.
-p Toggle the default pager option. cg has a bulit-in pager function, which can be enabled or disabled by default (in .cgvgrc). If the
default is enabled, this option disables the pager; if the default is disabled, this option enables it.
-P Force the built-in pager to be disabled.
FILES
${HOME}/.cglast
Log file of the last search.
${HOME}/.cgvgrc
Per-user configuration file (if the defaults are not desireable).
${HOME}/.cgvg/*
Log files in $HOSTNAME.shell_pid form with the log of the last search.
SEE ALSO vg(1), perl(1), find(1), grep(1), cscope(1)AUTHOR
cg was written by Joshua Uziel <uzi@uzix.org>.
13 Mar 2002 CG(1)