Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

On Ubuntu, how do you get all timestamps with file backup?

Ruby was much faster though so I think command should be faster not slower. Ruby was like instant. This is like take an hour.Here is like my current code.
Bash:
#!/bin/bash
#12/29/2023, 5:59PM, started, X E.
function startXE() {
    if [ -f "$1propsXE.txt" ]; then
        echo "$1propsXE.txt exists";
        rm -i "$1propsXE.txt";
        echo "File deleted";
    else
        echo "$1propsXE.txt does not exist";
    fi
    recurseXE $1 "$1propsXE.txt";
    echo "X E." >> "$1propsXE.txt";
    #X E.
}
#X E.
function recurseXE() {
    #save list of file name to variable
    manifest="$(ls -a $1 | grep -v /)";
    #echo "$(stat $1)";
    writeXE $1 $2;
    #iterate through each file name and pass it to stat to get birth, access, modify info
    while IFS= read -r line; do
        if [[ "$line" != ".." && "$line" != "." ]]; then
            if [ -d "$1$line" ]; then
                if [[ "$1$line" == */ ]]; then
                    recurseXE "$1$line" $2;
                else
                    recurseXE "$1$line/" $2;
                fi
                #echo "$line";
            else
                writeXE $1 $2;
            fi
        #echo "$1$line"
        fi
    done <<< $manifest
    #X E.
}
#X E.
function writeXE() {
    echo $1 >> $2;
    # Get the file's creation time using stat
    created_at=$(stat -c %W $1);
    # Get the timestamps using stat
    modified_at=$(stat -c %y $1);
    accessed_at=$(stat -c %x $1);
    changed_at=$(stat -c %z $1);
    # Format the creation time using the date command
    formatted_created_at=$(date -d @$created_at +"%Y-%m-%d %H:%M:%S.%N");
    # Format the timestamps using date
    formatted_modified_at=$(date -d "$modified_at" +"%Y-%m-%d %H:%M:%S.%N");
    formatted_accessed_at=$(date -d "$accessed_at" +"%Y-%m-%d %H:%M:%S.%N");
    formatted_changed_at=$(date -d "$changed_at" +"%Y-%m-%d %H:%M:%S.%N");
    echo $formatted_created_at >> $2;
    echo $formatted_modified_at >> $2;
    echo $formatted_accessed_at >> $2;
    echo $formatted_changed_at >> $2;
    echo "" >> $2;
    # Store the output of the stat command in a variable
    #output="$(stat $1)";
    #output=($output);
    # Use command substitution to split the output into an array
    #readarray -t stat_array <<< "$output";
    # Print the array elements
    #for element in "${stat_array[@]}"; do
     #   if [[ $element == *"Access:"* ]]; then
      #      echo "access";
       # fi
    #    if [[ $element == *"Modify:"* ]]; then
     #       echo "modify";
      #  fi
       # if [[ $element == *"Change:"* ]]; then
        #    echo "change";
        #fi
      #  if [[ $element == *"Birth:"* ]]; then
       #     echo "born";
       # fi
    #done
    #X E.
}
#X E.
if [ $# -gt 0 ]; then
    if [ -d "$1" ]; then
        if [[ "$1" == */ ]]; then
            startXE "$1";
        else
            startXE "$1/";
        fi
    fi
else
    if [[ "$(pwd)" == */ ]]; then
        startXE "$(pwd)";
    else
        startXE "$(pwd)/";
    fi
fi
#X E.
Also, an oddity of that, it is not actually deleting when I just press enter. Should it be y?
 
I found entering y works to delete that file. 13.2MB was size of Ruby generated file. If I could just make it with no variables inside writeXE then it would probably be like instant. X E.
 
Ruby was much faster though so I think command should be faster not slower. Ruby was like instant. This is like take an hour.Here is like my current code.
Bash:
#!/bin/bash
#12/29/2023, 5:59PM, started, X E.
function startXE() {
    if [ -f "$1propsXE.txt" ]; then
        echo "$1propsXE.txt exists";
        rm -i "$1propsXE.txt";
        echo "File deleted";
    else
        echo "$1propsXE.txt does not exist";
    fi
    recurseXE $1 "$1propsXE.txt";
    echo "X E." >> "$1propsXE.txt";
    #X E.
}
#X E.
function recurseXE() {
    #save list of file name to variable
    manifest="$(ls -a $1 | grep -v /)";
    #echo "$(stat $1)";
    writeXE $1 $2;
    #iterate through each file name and pass it to stat to get birth, access, modify info
    while IFS= read -r line; do
        if [[ "$line" != ".." && "$line" != "." ]]; then
            if [ -d "$1$line" ]; then
                if [[ "$1$line" == */ ]]; then
                    recurseXE "$1$line" $2;
                else
                    recurseXE "$1$line/" $2;
                fi
                #echo "$line";
            else
                writeXE $1 $2;
            fi
        #echo "$1$line"
        fi
    done <<< $manifest
    #X E.
}
#X E.
function writeXE() {
    echo $1 >> $2;
    # Get the file's creation time using stat
    created_at=$(stat -c %W $1);
    # Get the timestamps using stat
    modified_at=$(stat -c %y $1);
    accessed_at=$(stat -c %x $1);
    changed_at=$(stat -c %z $1);
    # Format the creation time using the date command
    formatted_created_at=$(date -d @$created_at +"%Y-%m-%d %H:%M:%S.%N");
    # Format the timestamps using date
    formatted_modified_at=$(date -d "$modified_at" +"%Y-%m-%d %H:%M:%S.%N");
    formatted_accessed_at=$(date -d "$accessed_at" +"%Y-%m-%d %H:%M:%S.%N");
    formatted_changed_at=$(date -d "$changed_at" +"%Y-%m-%d %H:%M:%S.%N");
    echo $formatted_created_at >> $2;
    echo $formatted_modified_at >> $2;
    echo $formatted_accessed_at >> $2;
    echo $formatted_changed_at >> $2;
    echo "" >> $2;
    # Store the output of the stat command in a variable
    #output="$(stat $1)";
    #output=($output);
    # Use command substitution to split the output into an array
    #readarray -t stat_array <<< "$output";
    # Print the array elements
    #for element in "${stat_array[@]}"; do
     #   if [[ $element == *"Access:"* ]]; then
      #      echo "access";
       # fi
    #    if [[ $element == *"Modify:"* ]]; then
     #       echo "modify";
      #  fi
       # if [[ $element == *"Change:"* ]]; then
        #    echo "change";
        #fi
      #  if [[ $element == *"Birth:"* ]]; then
       #     echo "born";
       # fi
    #done
    #X E.
}
#X E.
if [ $# -gt 0 ]; then
    if [ -d "$1" ]; then
        if [[ "$1" == */ ]]; then
            startXE "$1";
        else
            startXE "$1/";
        fi
    fi
else
    if [[ "$(pwd)" == */ ]]; then
        startXE "$(pwd)";
    else
        startXE "$(pwd)/";
    fi
fi
#X E.
Also, an oddity of that, it is not actually deleting when I just press enter. Should it be y?
... so I do have a question for ya... which would be faster, recursive v non-recursive? The answer may surprise you
 
... so I do have a question for ya... which would be faster, recursive v non-recursive? The answer may surprise you
I think non-recursive but I do not know how to do that. Also, if I just make it directly use what would be contents of manifest would that make it faster or slower? I also may try a global variable set for writeXE. I expect this thing would be faster in an environment where variables are made nearly only once. Next after this is how to set properties based on this recording using another Bash file. I am thinking maybe open source this thing and post it on a new thread in "Share with the community" when I get done. I should get your permission whatever I do with it other than personal use. Ruby was recursive too on this. X E.
 
I think non-recursive but I do not know how to do that. Also, if I just make it directly use what would be contents of manifest would that make it faster or slower? I also may try a global variable set for writeXE. I expect this thing would be faster in an environment where variables are made nearly only once. Next after this is how to set properties based on this recording using another Bash file. I am thinking maybe open source this thing and post it on a new thread in "Share with the community" when I get done. I should get your permission whatever I do with it other than personal use. Ruby was recursive too on this. X E.
You are actually correct. Non-recursive is the way to go. Here's a great resource for you on that.. I think the commentary speaks for itself.

Also regarding your commentary on not knowing how to do "non-recursive"...you may be overthinking it way more than you would like to admit lol. Non-recursive just means using loops 🙂
 
You are actually correct. Non-recursive is the way to go. Here's a great resource for you on that.. I think the commentary speaks for itself.

Also regarding your commentary on not knowing how to do "non-recursive"...you may be overthinking it way more than you would like to admit lol. Non-recursive just means using loops 🙂
recursion is a great thing... when you're only doing one thing... "lightning fast" in some cases. However, when performing too many tasks in recursion... you will take a big hit in speed/performance
 
... so I do have a question for ya... which would be faster, recursive v non-recursive? The answer may surprise you
Ok, so looking back, you're not really doing any recursion...you don't have the call to the function itself in order to make it recursive, that being the point of recursion. I think your function name is a bit misleading. Might want to rename it, for the sake of the sanity of anyone looking to help/take inspiration from your script, and for your own sake down the line lol. Trust me, I've been there myself plenty of times
 
That function recurseXE do recurse on itself if there is a folder. Here is like my current code and I think like my problem is that stat is too slow.
Bash:
#!/bin/bash
#12/29/2023, 5:59PM, started, X E. 9:04PM, like done but is slow. X E.
function startXE() {
    if [ -f "$1propsXE.txt" ]; then
        echo "$1propsXE.txt exists";
        rm -i "$1propsXE.txt";
        if [ -f "$1propsXE.txt" ]; then
            return;
        else
            echo "File deleted";
        fi
    else
        echo "$1propsXE.txt does not exist";
    fi
    recurseXE $1 "$1propsXE.txt";
    echo "X E." >> "$1propsXE.txt";
    echo "Done. X E.";
    #X E.
}
#X E.
function recurseXE() {
    if cantUseXE $1; then
        return;
    fi
    writeXE $1 $2;
    while IFS= read -r line; do
        if [[ "$line" != ".." && "$line" != "." ]]; then
            if [ -d "$1$line" ]; then
                if [[ "$1$line" == */ ]]; then
                    recurseXE "$1$line" $2;
                else
                    recurseXE "$1$line/" $2;
                fi
            else
                writeXE $1 $2;
            fi
        fi
    done <<< "$(ls -a $1 | grep -v /)"
    #X E.
}
#X E.
cr="";
mod="";
ac="";
ch="";
fcr="";
fmod="";
fac="";
fch="";
function writeXE() {
    if cantUseXE $1; then
        return;
    fi
    echo $1 >> $2;
    cr=$(stat -c %w $1);
    mod=$(stat -c %y $1);
    ac=$(stat -c %x $1);
    ch=$(stat -c %z $1);
    fcr=$(date -d "$cr" +"%Y-%m-%d %H:%M:%S.%N %Z");
    fmod=$(date -d "$mod" +"%Y-%m-%d %H:%M:%S.%N %Z");
    fac=$(date -d "$ac" +"%Y-%m-%d %H:%M:%S.%N %Z");
    fch=$(date -d "$ch" +"%Y-%m-%d %H:%M:%S.%N %Z");
    echo $fcr >> $2;
    echo $fmod >> $2;
    echo $fac >> $2;
    echo $fch >> $2;
    echo "" >> $2;
    #X E.
}
#X E.
#12/30/2023, 11:07AM, start. 11:09AM, like done, X E. 11:11AM like done.
function cantUseXE() {
    if [ -r "$1" ]; then
        return 1;
    else
        echo 0;
    fi
    #X E.
}
#X E.
if [ $# -gt 0 ]; then
    if [ -d "$1" ]; then
        if [[ "$1" == */ ]]; then
            startXE "$1";
        else
            startXE "$1/";
        fi
    fi
else
    if [[ "$(pwd)" == */ ]]; then
        startXE "$(pwd)";
    else
        startXE "$(pwd)/";
    fi
fi
#X E.
I tried making it auto format and removing those formatted variables and it wrote about same and same speed. cantUseXE is so no errors and only record what I can. X E.
 
Oops, echo not return in new function, fixed. Also, here is what I have so far for setting.
Bash:
#!/bin/bash

#12/28/2023, 9:26PM, start, X E. 9:55PM, done for today. X E. 9:59PM, like done for today, X E.
# Specify the file path
file_path="$(pwd)/propsXE.txt";
#created_at=$(date -d "2023-12-20 10:27:29 -0500" +%s)
# Check if the file exists
if [ -f "$file_path" ]; then
  # Open the file for reading
  exec 3< "$file_path"
 
  index=0;
  res=0;
  # Read each line of the file
  while IFS= read -r line <&3; do
    # Process the line
    echo $index;
    index=$((index+1));
    if [ $index -eq 6 ]; then
      index=0
    fi
  done

  # Close the file
  exec 3<&-
else
  echo "File not found: $file_path"
fi
#X E.
X E.
 
This is like my current code and it is slow but as fast as I can make it.
Bash:
#!/bin/bash
#12/29/2023, 5:59PM, started, X E. 9:04PM, like done but is slow. X E.
function startXE() {
    if [ -f "$1propsXE.txt" ]; then
        echo "$1propsXE.txt exists";
        rm -i "$1propsXE.txt";
        if [ -f "$1propsXE.txt" ]; then
            return;
        else
            echo "File deleted";
        fi
    else
        echo "$1propsXE.txt does not exist";
    fi
    recurseXE $1 "$1propsXE.txt";
    echo "X E." >> "$1propsXE.txt";
    echo "Done. X E.";
    #X E.
}
#X E.
function recurseXE() {
    if cantUseXE $1; then
        return;
    fi
    writeXE $1 $2;
    while IFS= read -r line; do
        if [[ "$line" != ".." && "$line" != "." ]]; then
            if [ -d "$1$line" ]; then
                if [[ "$1$line" == */ ]]; then
                    recurseXE "$1$line" $2;
                else
                    recurseXE "$1$line/" $2;
                fi
            else
                writeXE "$1$line" $2;
            fi
        fi
    done <<< "$(ls -a $1 | grep -v /)"
    #X E.
}
#X E.
cr="";
mod="";
ac="";
ch="";
fcr="";
fmod="";
fac="";
fch="";
file="";
function writeXE() {
    if cantUseXE $1; then
        return;
    fi
    echo $1 >> $2;
    file=($(stat -c "%w %y %x %z" $1));
    #fcr=$(date -d "${file[0]} ${file[1]} ${file[2]}" +"%Y-%m-%d %H:%M:%S.%N %Z");
    #fmod=$(date -d "${file[3]} ${file[4]} ${file[5]}" +"%Y-%m-%d %H:%M:%S.%N %Z");
    #fac=$(date -d "${file[6]} ${file[7]} ${file[8]}" +"%Y-%m-%d %H:%M:%S.%N %Z");
    #fch=$(date -d "${file[9]} ${file[10]} ${file[11]}" +"%Y-%m-%d %H:%M:%S.%N %Z");
    echo "${file[0]} ${file[1]} ${file[2]}" >> $2;
    echo "${file[3]} ${file[4]} ${file[5]}" >> $2;
    echo "${file[6]} ${file[7]} ${file[8]}" >> $2;
    echo "${file[9]} ${file[10]} ${file[11]}" >> $2;
    echo "" >> $2;
    #X E.
}
#X E.
#12/30/2023, 11:07AM, start. 11:09AM, like done, X E. 11:11AM like done.
function cantUseXE() {
    if [ -r "$1" ]; then
        return 1;
    else
        return 0;
    fi
    #X E.
}
#X E.
if [ $# -gt 0 ]; then
    if [ -d "$1" ]; then
        if [[ "$1" == */ ]]; then
            startXE "$1";
        else
            startXE "$1/";
        fi
    fi
else
    if [[ "$(pwd)" == */ ]]; then
        startXE "$(pwd)";
    else
        startXE "$(pwd)/";
    fi
fi
#X E.
It is apparently that looping like you said but I am unsure how to fix that. It has a variable number of loops inside loops so I am unsure how to do it. X E.
 
Here is a faulty zzzcode.ai thing but it does have an idea enclosed.
Bash:
#!/bin/bash
#12/29/2023, 5:59PM, started, X E. 9:04PM, like done but is slow. X E.
function startXE() {
    if [ -f "$1propsXE.txt" ]; then
        echo "$1propsXE.txt exists";
        rm -i "$1propsXE.txt";
        if [ -f "$1propsXE.txt" ]; then
            return;
        else
            echo "File deleted";
        fi
    else
        echo "$1propsXE.txt does not exist";
    fi

    stack=("$1")
    while [ ${#stack[@]} -gt 0 ]; do
        current_dir="${stack[-1]}"
        unset 'stack[${#stack[@]}-1]'

        if cantUseXE "$current_dir"; then
            continue;
        fi

        writeXE "$current_dir" "$1propsXE.txt"

        while IFS= read -r line; do
            if [[ "$line" != ".." && "$line" != "." ]]; then
                if [ -d "$current_dir$line" ]; then
                    stack+=("$current_dir$line/")
                else
                    writeXE "$current_dir$line" "$1propsXE.txt"
                fi
            fi
        done <<< "$(ls -a $current_dir | grep -v /)"
    done

    echo "X E." >> "$1propsXE.txt";
    echo "Done. X E.";
}

cr="";
mod="";
ac="";
ch="";
fcr="";
fmod="";
fac="";
fch="";
file="";
function writeXE() {
    if cantUseXE $1; then
        return;
    fi
    echo $1 >> $2;
    file=($(stat -c "%w %y %x %z" $1));
    echo "${file[0]} ${file[1]} ${file[2]}" >> $2;
    echo "${file[3]} ${file[4]} ${file[5]}" >> $2;
    echo "${file[6]} ${file[7]} ${file[8]}" >> $2;
    echo "${file[9]} ${file[10]} ${file[11]}" >> $2;
    echo "" >> $2;
}

#12/30/2023, 11:07AM, start. 11:09AM, like done, X E. 11:11AM like done.
function cantUseXE() {
    if [ -r "$1" ]; then
        return 1;
    else
        return 0;
    fi
}

if [ $# -gt 0 ]; then
    if [ -d "$1" ]; then
        if [[ "$1" == */ ]]; then
            startXE "$1";
        else
            startXE "$1/";
        fi
    else
        if [ -f "$1propsXE.txt" ]; then
            echo "$1propsXE.txt exists";
            rm -i "$1propsXE.txt";
            if [ -f "$1propsXE.txt" ]; then
                return;
            else
                echo "File deleted";
            fi
        else
            echo "$1propsXE.txt does not exist";
        fi
        writeXE $1 "$1propsXE.txt";
        echo "X E." >> "$1propsXE.txt";
        echo "Done. X E.";
    fi
else
    if [[ "$(pwd)" == */ ]]; then
        startXE "$(pwd)";
    else
        startXE "$(pwd)/";
    fi
fi
#X E
I would not run that but there is an idea about that. X E.
 
Okay this almost works but it does not handle paths with spaces properly.
Bash:
#!/bin/bash
#12/29/2023, 5:59PM, started, X E. 9:04PM, like done but is slow. X E.
function startXE() {
    if [ -f "$1propsXE.txt" ]; then
        echo "$1propsXE.txt exists";
        rm -i "$1propsXE.txt";
        if [ -f "$1propsXE.txt" ]; then
            return;
        else
            echo "File deleted";
        fi
    else
        echo "$1propsXE.txt does not exist";
    fi

    stack=("$1")
    while [ ${#stack[@]} -gt 0 ]; do
        current_dir="${stack[-1]}"
        unset 'stack[${#stack[@]}-1]'

        if cantUseXE "$current_dir"; then
            continue;
        fi

        writeXE "$current_dir" "$1propsXE.txt"

        while IFS= read -r line; do
            if [[ "$line" != ".." && "$line" != "." ]]; then
                if [ -d "$current_dir$line" ]; then
                    if [[ "$current_dir$line" == */ ]]; then
                        stack+=("$current_dir$line")
                    else
                        stack+=("$current_dir$line/")
                    fi
                else
                    writeXE "$current_dir$line" "$1propsXE.txt"
                fi
            fi
        done <<< "$(ls -a $current_dir | grep -v /)"
    done

    echo "X E." >> "$1propsXE.txt";
    echo "Done. X E.";
}
#X E.
function recurseXE() {
    if cantUseXE $1; then
        return;
    fi
    writeXE $1 $2;
    while IFS= read -r line; do
        if [[ "$line" != ".." && "$line" != "." ]]; then
            if [ -d "$1$line" ]; then
                if [[ "$1$line" == */ ]]; then
                    recurseXE "$1$line" $2;
                else
                    recurseXE "$1$line/" $2;
                fi
            else
                writeXE "$1$line" $2;
            fi
        fi
    done <<< "$(ls -a $1 | grep -v /)"
    #X E.
}
#X E.
cr="";
mod="";
ac="";
ch="";
fcr="";
fmod="";
fac="";
fch="";
file="";
function writeXE() {
    if cantUseXE $1; then
        return;
    fi
    echo $1 >> $2;
    file=($(stat -c "%w %y %x %z" $1));
    #fcr=$(date -d "${file[0]} ${file[1]} ${file[2]}" +"%Y-%m-%d %H:%M:%S.%N %Z");
    #fmod=$(date -d "${file[3]} ${file[4]} ${file[5]}" +"%Y-%m-%d %H:%M:%S.%N %Z");
    #fac=$(date -d "${file[6]} ${file[7]} ${file[8]}" +"%Y-%m-%d %H:%M:%S.%N %Z");
    #fch=$(date -d "${file[9]} ${file[10]} ${file[11]}" +"%Y-%m-%d %H:%M:%S.%N %Z");
    echo "${file[0]} ${file[1]} ${file[2]}" >> $2;
    echo "${file[3]} ${file[4]} ${file[5]}" >> $2;
    echo "${file[6]} ${file[7]} ${file[8]}" >> $2;
    echo "${file[9]} ${file[10]} ${file[11]}" >> $2;
    echo "" >> $2;
    #X E.
}
#X E.
#12/30/2023, 11:07AM, start. 11:09AM, like done, X E. 11:11AM like done.
function cantUseXE() {
    if [ -r "$1" ]; then
        return 1;
    else
        return 0;
    fi
    #X E.
}
#X E.
if [ $# -gt 0 ]; then
    if [ -d "$1" ]; then
        if [[ "$1" == */ ]]; then
            startXE "$1";
        else
            startXE "$1/";
        fi
    else
        if [ -f "$1propsXE.txt" ]; then
            echo "$1propsXE.txt exists";
            rm -i "$1propsXE.txt";
            if [ -f "$1propsXE.txt" ]; then
                return;
            else
                echo "File deleted";
            fi
        else
            echo "$1propsXE.txt does not exist";
        fi
        writeXE $1 "$1propsXE.txt";
        echo "X E." >> "$1propsXE.txt";
        echo "Done. X E.";
    fi
else
    if [[ "$(pwd)" == */ ]]; then
        startXE "$(pwd)";
    else
        startXE "$(pwd)/";
    fi
fi
#X E.
What can I do? I saved old code that worked slow. X E.
 
Only problem is it hangs on this and will not continue to after it.

Nexus 7 (2013) Wi-Fi

It has no such directory 7, no such directory (2013), no such directory Wi-Fi. What can be fixed? That is with directory to it before it. X E.
 
I just tested and it has directory correct but error is coming from ls in that. I just tested and original before loops has no error when running all way through. X E.
 
I fixed it but it is still slow.
Bash:
#!/bin/bash
#12/29/2023, 5:59PM, started, X E. 9:04PM, like done but is slow. X E.
function startXE() {
    if [ -f "$1propsXE.txt" ]; then
        echo "$1propsXE.txt exists";
        rm -i "$1propsXE.txt";
        if [ -f "$1propsXE.txt" ]; then
            return;
        else
            echo "File deleted";
        fi
    else
        echo "$1propsXE.txt does not exist";
    fi

    stack=("$1")
    while [ ${#stack[@]} -gt 0 ]; do
        current_dir="${stack[-1]}"
        unset 'stack[${#stack[@]}-1]'

        if cantUseXE "$current_dir"; then
            continue;
        fi

        writeXE "$current_dir" "$1propsXE.txt"
        while IFS= read -r line; do
            if [[ "$line" != ".." && "$line" != "." ]]; then
                if [ -d "$current_dir$line" ]; then
                    if [[ "$current_dir$line" == */ ]]; then
                        stack+=("$current_dir$line")
                    else
                        stack+=("$current_dir$line/")
                    fi
                else
                    if cantUseXE "$current_dir"; then
                        continue;
                    fi
                    writeXE "$current_dir$line" "$1propsXE.txt"
                fi
            fi
        done <<< "$(ls -a "$current_dir" | grep -v /)"
    done

    echo "X E." >> "$1propsXE.txt";
    echo "Done. X E.";
}
#X E.
function recurseXE() {
    writeXE $1 $2;
    while IFS= read -r line; do
        if [[ "$line" != ".." && "$line" != "." ]]; then
            if [ -d "$1$line" ]; then
                if [[ "$1$line" == */ ]]; then
                    recurseXE "$1$line" $2;
                else
                    recurseXE "$1$line/" $2;
                fi
            else
                writeXE "$1$line" $2;
            fi
        fi
    done <<< "$(ls -a $1 | grep -v /)"
    #X E.
}
#X E.
cr="";
mod="";
ac="";
ch="";
fcr="";
fmod="";
fac="";
fch="";
file="";
function writeXE() {
    if cantUseXE $1; then
        return;
    fi
    echo $1 >> $2;
    file=($(stat -c "%w %y %x %z" $1));
    #fcr=$(date -d "${file[0]} ${file[1]} ${file[2]}" +"%Y-%m-%d %H:%M:%S.%N %Z");
    #fmod=$(date -d "${file[3]} ${file[4]} ${file[5]}" +"%Y-%m-%d %H:%M:%S.%N %Z");
    #fac=$(date -d "${file[6]} ${file[7]} ${file[8]}" +"%Y-%m-%d %H:%M:%S.%N %Z");
    #fch=$(date -d "${file[9]} ${file[10]} ${file[11]}" +"%Y-%m-%d %H:%M:%S.%N %Z");
    echo "${file[0]} ${file[1]} ${file[2]}" >> $2;
    echo "${file[3]} ${file[4]} ${file[5]}" >> $2;
    echo "${file[6]} ${file[7]} ${file[8]}" >> $2;
    echo "${file[9]} ${file[10]} ${file[11]}" >> $2;
    echo "" >> $2;
    #X E.
}
#X E.
#12/30/2023, 11:07AM, start. 11:09AM, like done, X E. 11:11AM like done.
function cantUseXE() {
    if [ -e "$1" ]; then
        return 1;
    else
        return 0;
    fi
    #X E.
}
#X E.
if [ $# -gt 0 ]; then
    if [ -d "$1" ]; then
        if [[ "$1" == */ ]]; then
            startXE "$1";
        else
            startXE "$1/";
        fi
    else
        if [ -f "$1propsXE.txt" ]; then
            echo "$1propsXE.txt exists";
            rm -i "$1propsXE.txt";
            if [ -f "$1propsXE.txt" ]; then
                return;
            else
                echo "File deleted";
            fi
        else
            echo "$1propsXE.txt does not exist";
        fi
        writeXE $1 "$1propsXE.txt";
        echo "X E." >> "$1propsXE.txt";
        echo "Done. X E.";
    fi
else
    if [[ "$(pwd)" == */ ]]; then
        startXE "$(pwd)";
    else
        startXE "$(pwd)/";
    fi
fi
#X E.
I think it was actually faster with recursion. X E.
 
A complete and working one with no recursion.
Bash:
#!/bin/bash
#12/29/2023, 5:59PM, started, X E. 9:04PM, like done but is slow. X E.
function startXE() {
    if [ -f "$1propsXE.txt" ]; then
        echo "$1propsXE.txt exists";
        rm -i "$1propsXE.txt";
        if [ -f "$1propsXE.txt" ]; then
            return;
        else
            echo "File deleted";
        fi
    else
        echo "$1propsXE.txt does not exist";
    fi

    stack=("$1")
    while [ ${#stack[@]} -gt 0 ]; do
        current_dir="${stack[-1]}"
        unset 'stack[${#stack[@]}-1]'
        if cantUseXE "$current_dir"; then
            continue;
        fi
        manifest="$(ls -a "$current_dir" | grep -v /)"
        writeXE "$current_dir" "$1propsXE.txt"
        while IFS= read -r line; do
            if [[ "$line" != ".." && "$line" != "." ]]; then
                if [ -d "$current_dir$line" ]; then
                    if [[ "$current_dir$line" == */ ]]; then
                        stack+=("$current_dir$line")
                    else
                        stack+=("$current_dir$line/")
                    fi
                else
                    writeXE "$current_dir$line" "$1propsXE.txt"
                fi
            fi
        done <<< $manifest
    done

    echo "X E." >> "$1propsXE.txt";
    echo "Done. X E.";
}
#X E.
function writeXE() {
    if cantUseXE $1; then
        return;
    fi
    echo $1 >> $2;
    file=($(stat -c "%w %y %x %z" $1));
    echo "${file[0]} ${file[1]} ${file[2]}" >> $2;
    echo "${file[3]} ${file[4]} ${file[5]}" >> $2;
    echo "${file[6]} ${file[7]} ${file[8]}" >> $2;
    echo "${file[9]} ${file[10]} ${file[11]}" >> $2;
    echo "" >> $2;
    #X E.
}
#X E.
#12/30/2023, 11:07AM, start. 11:09AM, like done, X E. 11:11AM like done.
function cantUseXE() {
    if [ -e "$1" ]; then
        return 1;
    else
        return 0;
    fi
    #X E.
}
#X E.
if [ $# -gt 0 ]; then
    if [ -d "$1" ]; then
        if [[ "$1" == */ ]]; then
            startXE "$1";
        else
            startXE "$1/";
        fi
    else
        if [ -f "$1propsXE.txt" ]; then
            echo "$1propsXE.txt exists";
            rm -i "$1propsXE.txt";
            if [ -f "$1propsXE.txt" ]; then
                return;
            else
                echo "File deleted";
            fi
        else
            echo "$1propsXE.txt does not exist";
        fi
        writeXE $1 "$1propsXE.txt";
        echo "X E." >> "$1propsXE.txt";
        echo "Done. X E.";
    fi
else
    if [[ "$(pwd)" == */ ]]; then
        startXE "$(pwd)";
    else
        startXE "$(pwd)/";
    fi
fi
#X E.
Apparently like my Bash is really slow. It does about 100kB per second. Ruby does about 10MB per second and writes more in. Why would like native be slower than some like interpreted language? Something is fishy about this. I know that this current version is fastest I can get nearly and works. Maybe try it in your system because it could maybe be just like my system. X E.
 

New Threads

Buy us a coffee!

Back
Top Bottom