Hi everyone,
I'm trying to write a script that will list all files and their details within a directory - so for example, if I have the structure
/home/
/home/folder1/
/home/folder2/
/home/folder3/
It will print something like
+----------------------------
| /home/folder1/
+----------------------------
| *files here* | *size*
+----------------------------
| /home/folder2
+----------------------------
| *files here* | *size*
Although I seem to be having a bit of trouble so far - it will list all the files in one go, which is not what I want, they need to be separated by directory!
Does anyone know anyw way of doing this? I can post some code if anyone wants too take a look at it, and many thanks in advance :)
#!/bin/bash
OUTPUT=""
TAQ_FILES=""
DQR_FILES=""
TAQ_MD5=""
DQR_MD5=""
CURRENT_DIR=`pwd`
for dir in $(find $CURRENT_DIR -type d);
do
cd $dir
echo "Currently Processing Files in $dir"
OUTPUT=$OUTPUT"+-----------------------------------------------------------------------------------------------------+\n"
OUTPUT=$OUTPUT"| TAQ Report for $dir\n"
OUTPUT=$OUTPUT"+-----------------------------------------------------------------------------------------------------+\n"
OUTPUT=$OUTPUT"| TAQ Files : `ls -l *.gz | wc -l` Total (`ls -l TAQ*.md5 | wc -l` md5 check sums); DQR Files : `ls -l *.txt | wc -l` Total (`ls -l DATA*.md5 | wc -l` md5 check sums) |\n"
OUTPUT=$OUTPUT"+-----------------------------------------------------------------------------------------------------+\n"
OUTPUT=$OUTPUT"| TAQ Files in directory\t\t\t\t\t| Size \t\t| MD5 Sum?\t\t|\n"
OUTPUT=$OUTPUT"+-----------------------------------------------------------------------------------------------------+\n"
for file in $dir $(find -type f -iname "TAQ*.gz");
do
if [ $dir == $CURRENT_DIR ];
then
# echo "home"
#else
TAQ_FILES=$TAQ_FILES"| `basename $file .csv.gz`\t\t\t\t| `ls -lh $file | awk '{print $5}'`\t\t|\n"
if [ -e `basename $file .csv.gz`.md5 ];
then
echo `basename $file .csv.gz`.md5
echo "md5 exists for $file"
fi
fi
done
OUTPUT=$OUTPUT$TAQ_FILES
OUTPUT=$OUTPUT"+-----------------------------------------------------------------------------------------------------+\n"
for file in $dir $(find -type f -iname "DATA*.txt");
do
if [ $dir == $CURRENT_DIR ];
then
# echo "home"
#else
DQR_FILES=$DQR_FILES"| `basename $file .txt`\t\t\t\t| `ls -lh $file | awk '{print $5}'`\t\t|\n"
# if [];
# then
# fi
fi
done
OUTPUT=$OUTPUT$DQR_FILES
OUTPUT=$OUTPUT"+-----------------------------------------------------------------------------------------------------+\n"
DQR_FILES=""
TAQ_FILES=""
echo -e $OUTPUT >> test.txt
done