Shell script to delete empty files from specific locations

Hi,
I need help in regard to developing a shell script to delete empty files from multiple specific locations. The directory paths will be stored in a text file. So the requirement is to read the text file for one specific path and then remove empty files from that particular path. Looping through till end of the text file where path locations are defined.

Any template to meet this requirement will be greatly appreciated.

Contents of the file where multiple specified paths will be mentioned:

/b02/apps/appsoutput/UAT/INTERFACES
/b02/apps/appsoutput/UAT/FTP_XXSRDLS/stderr
/b02/apps/appsoutput/UAT/SORT_XXMRLP/stderr
/b02/apps/appsoutput/UAT/SORT_XXMRDP/stderr
/b02/apps/appsoutput/UAT/FTP_XXMRUP/stderr
/b02/apps/appsoutput/UAT/FTP_XXMRLP/stderr
/b02/apps/appsoutput/UAT/FTP_XXSRDL/stderr
/b02/apps/appsoutput/UAT/FTP_XXSRUPV/stderr
/b02/apps/appsoutput/UAT/SORT_XXMRDPQ/stderr
/b02/apps/appsoutput/UAT/SORT_XXMRDPQ/stderr
/b02/apps/appsoutput/UAT/SORT_XXMRLPQ/stderr
/b02/apps/appsoutput/UAT/SORT_XXMRLPQ/stderr
/b02/apps/appsoutput/UAT/XXMRDPNT/reports
/b02/apps/appsoutput/UAT/SORT_XXMRDPS/stderr

Hello Khan28,

Could you please try following and let me know if this helps you(haven't tested it though).

while read path
do
    find $path -type f -size 0 -print
done < "Input_file"
 

Thanks,
R. Singh

1 Like

Hi R.Singh,

Thanks for your reply. I am facing some problems:

I have tried to make the shell script as:

Directory path containing file:

 vim pathfile.txt
/d02/apps/output/UAT/CMFUP/reports
while IFS='' read -r  path;
do
name="$path"
echo "Finding Empty Files from location - $name"
find  $name -empty -print
done < "$1"

ran by executing

 ./CM_Del_Emp_files.sh pathfile.txt

Results in ERROR:

sysadm@xxxh016:[UAT:NRDP]:/d01/apps/ccb/UAT/scripts/cm> ./CM_Del_Emp_files.sh pathfile.txt
Finding Empty Files from location - /d02/apps/ccboutput/UAT/CMFUP/reports
find: `/d02/apps/output/UAT/CMFUP/reports\r': No such file or directory

It looks like the editor you used to create pathfile.txt was set up to use DOS (<carriage-return><newline> character pair) line terminators instead of UNIX (<newline> single character) line terminators. The extra <carriage-return> character at the end of the line is being interpreted as part of the pathname of the file; not as part of the line terminator.

1 Like

Thanks All. It worked. Created a new file in Linux directly and copying directory path in that.

touch pathfile.txt
vim pathfile.txt
/p02/apps/output/UAT/CMXSU/reports/