I'm trying to create two very similar scripts. One script is to list all files in a directory and then subdirectories, subdirectories of subdirectories, and so on and so on until there are no more directories and then output the info to a log file with the path name starting from the directory I started from. The other script is to do exactly the same as above, but instead of the directories, I need it to list all the files within those directories and subdirectories. I also need the path names starting from the directory I started from. They both need to output in separate log files, however.
I need to do this in either sed commands or bash commands compatible with android.
/system/ denotes the directory I want to start from
This outputs just the directories in /system/ and successfully makes a log file:
LOG_FILE=/data/local/log.log;
for d in /system/*; do [[ -f "$d" ]] || echo "$d" "$d"| tee -a $LOG_FILE; done
This outputs just the files in /system/ and successfully makes a log file:
LOG_FILE=/data/local/log.log;
for f in /system/*; do [[ -d "$f" ]] || echo "$f" "$f"| tee -a $LOG_FILE; done
Unfortunately I've been unsuccessful searching here or anywhere else to find how to do it properly. I'm almost certain I can't do it recursively in the Android system I'm working with. I think that all I have to work with is sed and bash in a limited manner.
Any help would be appreciated.
EDIT: So I forgot to add that I need to add lines to the beginning and ending of each line in the file in the fashion below, but with the above changes i need.
LOG_FILE=/local/log.log;
tmp1="cp"
tmp2=tmp
tmp3=test
for f in /system/*; do [[ -d "$f" ]] || echo $tmp1 $tmp2/$tmp3"$f" "$f"| tee -a $LOG_FILE; done
So it would output like this with /system/file.txt being the path i need to replicate (denoted by "$f"):
cp tmp/test/system/file.txt system/file.txt
cp tmp/test/system/file2.txt system/file2.txt
This should work for the directories:
find /system/ -type d -print > $LOG_FILE
and this should get you the files list:
find /system/ -type f -print > $LOG_FILE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With