• 4 Posts
  • 17 Comments
Joined 18 days ago
cake
Cake day: January 14th, 2025

help-circle

  • Ok, thanks for the tip. I’m still getting used to Lemmy.

    I ended up using

    for f in *; do find ./“$f” -type f | sort | tail -n 2 | xargs -n 1 rm; done

    and it worked perfectly. For the bonus question, I’m moving the html files from 127 subfolders. They are the only content of the subfolders. I want to prepend an integer to each and copy them to a different folder, so instead of

    • folder1/file1
    • folder1/file2
    • folder2/file1
    • folder2/file2
    • folder2/file3

    I’ll have

    • 001file1
    • 002file2
    • 003file1
    • 004file2
    • 005file3

  • 😍😍😍😍 thanks harsh!! I’ll study this and report back. I really appreciate your time and effort. There is a lot to learn here, and actually the padding is on my list of things to learn, so thank you sensei! As to your question about the integers, the files need to be in alphabetical order before getting the integer prepended to them, so like

    • folder1/file1
    • folder1/file2
    • folder2/file1
    • folder2/file2
    • folder2/file3

    turns to

    • folder1/001file1
    • folder1/002file2
    • folder2/003file1
    • folder2/004file2
    • folder2/005file3

    that way in the folder when it’s all said and done I’ll have

    • 001file1
    • 002file2
    • 003file1
    • 004file2
    • 005file3

    I’ll check if your method works out of the box for that or if I have to use the sort function like you showed me last time. Thanks again!