@aliyesami
The script you found on the web contains basic scripting errors.
Quote:
#!/usr/bin/bash
printf "Enter start date( YYYYMMDD ):"
read startdate
printf "Enter end date( YYYYMMDD ):"
read enddate
touch -t "${startdate}0000.00" sdummy
touch -t "${enddate}0000.00" edummy
for fi in *
do
if [ $fi -nt "sdummy" -a ! $fi -nt "edummy" ] ;then
echo ls -al $fi
fi
done
Never use this construct for open-ended lists of files. It breaks if any filename contains a space character and it breaks the Shell if there are too many files.
The shebang line is for "bash" when you have "ksh".
The script does not check the type of inode. If it comes across a directory it will break.
The script logic will ignore anything created on the end date.
The script creates the reference files in the directory you are searching.
The line starting "echo" stops the "ls" executing.
The "find" approach is best.
@balajesuri
The script you post is interesting but the O/P has "ksh" not "bash" and probably won't have a Linux "stat" command.
The script contains similar errors to that posted by the O/P.
Quote:
for file in `ls | grep -v "^d"`
This will ignore every file with a name starting with a lower case "d". It will not ignore directories. Never use "for" to process a directory list.
I'm still searching for any course, book or manual which advocates using "for" with an open-ended list of filenames. This construct must have come from somewhere!