0
cd /DIR1/

if [ -f  abc_*] ; then

ls -l abc_*| awk 'NR >0 && !/^d/ {print $NF}' >>list.txt

chmod 664 list.txt

else

echo "file not found"

fi

it giving the error as "Binary Operator expected "

If any files found in the directory starting with the pattern "abc_" it should create a file called list.txt and move the filenames to list.txt

mike3996
  • 17,047
  • 9
  • 64
  • 80
RonuRaj
  • 9
  • 1
  • 3
  • 4
  • possible duplicate: http://stackoverflow.com/questions/24603037/binary-operator-expected-error-when-checking-if-a-file-with-full-pathname-exists or http://stackoverflow.com/questions/8340144/please-help-me-binary-operator-expected-in-cygwin – jaynp Nov 20 '14 at 07:52

2 Answers2

0

-f checks for the existance of a single file, you can rather use

if ls abc_* 2>/dev/null; then 
  do stuff
fi
Decado
  • 356
  • 2
  • 15
0

You could just use single liner find command like below:

find . -maxdepth 1 -name "abc_*" -printf "%f\n" >> list.txt

find command will find your files in current (replace . with /DIR1 to find in /DIR1) directory

  • maxdepth - just in directory specified and not recursively within each directories.
  • name name like abc_*
  • printf - print just the file name without directory prefixed.
Infinite Recursion
  • 6,511
  • 28
  • 39
  • 51
SMA
  • 36,381
  • 8
  • 49
  • 73