Through script I am not able to change into directories and list the files.
cd
is not working.
Here is my script
#!/bin/bash
export HOME=/home/yesh
DIR_START=2
DIR_END=`wc -l < ${HOME}/conf/DirectoryList`
while [ ${DIR_START} -le ${DIR_END} ];
do
DIR1=`cat /home/yesh/conf/DirectoryList | sed -ne ${DIR_START}p`
echo "cd ${HOME}/${DIR1}"
find . -type f > /home/yesh/Files_"$(date +%Y%d%m)".log
done
DirectoryList
/home/yesh/yesh.txt
/home/yesh/Yesh
/home/yesh/BACKUP
/home/yesh/venv3
/home/yesh/pythonfund
The above are the list of directories I need to navigate through in ${HOME}/conf/DirectoryList
If the list of directories is not too large, I'd suggest avoiding the shell loop altogether and simply passing the list to
find
via an array:If you still want to use a shell loop instead, then
If the intent of your
cd
was to remove the leading path components from the output, then you can do that withinfind
by replacing the default print by an explicit-printf '%P\n'