Home > OS >  List all the files for current date from a present working directory into a new file
List all the files for current date from a present working directory into a new file

Time:03-22

I am trying to get the filenames for all the files listed in my current directory for current date and list them into a new file in same path.

#!/bin/bash
for file in /queues/intermediate/outbound/*EXP_GP_$(date %Y-%m-%d)* do  f1=`basename $file`
if [ -f "$file" ];then
        cat >> All_Name $f1;
else
    echo "no files to collect"
 done

CodePudding user response:

this works

find -maxdepth 1 -mtime -1 | grep -v bash | grep / | sed 's/\.\///' > FileList.txt

CodePudding user response:

Try this:

#!/bin/bash

for file in /queues/intermediate/outbound/\*EXP_GP_$(date  %Y-%m-%d)\*
do

f1=`basename $file`

if [ -f "$file" ]; then
        cat >> All_Name $f1;
else
    echo "no files to collect"
fi

done

There was also a 'fi' missing.

  • Related