• talkingpumpkin@lemmy.world
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    5 hours ago

    IDK.

    I just asked this to perplexity as an experiment:

    write a macos terminal command that makes a backup copy if all files in documents/ my home adding the current date and time to each filename

    Here’s what it concocted:

    cd ~ && find Documents -maxdepth 1 -type f -exec sh -c 'for f; do cp "$1" "Documents/$(date +%Y%m%d-%H%M%S)_$(basename "$1")"; done' _ {} +
    

    Now, I am no “prompt engineer” and surely there are better way to ask it stuff, but then again a layman is no prompt engineer either.

    So the question is: would a layman be able to provide feedback and have perplexity fix its command?

    My “layman-like” feedback (now that I re-read it, IDK how much a layman would have used “recurse”… I’m doing my best here):

    I want the files copied to a “backups” folder in my home. It should also recurse into the “documents” folder.

    mkdir -p ~/backups && cd ~/Documents && find . -type f -exec sh -c 'mkdir -p "~/backups/$(dirname "$1")" && cp "$1" "~/backups/$2/$(date +%Y%m%d-%H%M%S)_$(basename "$1")"' _ {} "$(pwd)" \;
    

    Feeback:

    it says “No such file or directory” (because of $PWD passed as $2 - of course I didn’t say this to the LLM)

    mkdir -p ~/backups && rsync -a --include='*/' --include='*.*' --exclude='*' --no-links ~/Documents/ ~/backups/"$(date +%Y%m%d-%H%M%S)"/
    

    the date must be in the file name

    mkdir -p ~/backups && find ~/Documents -type f -exec sh -c 'dir="~ /backups/$(dirname "${1#"$2"}")"; mkdir -p "$dir"; cp "$1" "$dir/$(date +%Y%m%d-%H%M%S)_$(basename "$1")"' _ {} ~/Documents \;
    

    I don’t think I need to continue?

    BTW: the LLM also instructed me to do a whole bunch of seemingly useless stuff, like giving Terminal.app full disk access via System Settings > Privacy & Security > Full Disk Access (which I assume is actually a thing in macos but can’t verify as I run linux)

    edit: I hope I didn’t misinterpret the bash commands (I didn’t actually run them) and spotted the right bugs in them - even if I didn’t I guess my point still stands?