I see it needs to be done very differently, with different scripts.

  1. Simplify the file names, remove the beginning.

    The 1st script would be to greatly simplify the file names. There’s mess now, each file is too complex. Remove everything and leave only the long coded message. E.g. a file name How to Reduce Your Email Checking to Once A Day Fa 0145b1155a404ba09fc6996fe90586c8 becomes just a 0145b1155a404ba09fc6996fe90586c8. I need to rename all files, and all files+directories combinations. If there’s a directory, then in the file, there’s be a path, it needs to be cleaned everything before this name.

    The prompt could be:

    Help me write a bash script for a Linux system.

    I have a directory of markdown files and directories.

    1. Check each markdown file inside the directory. Its name would be complex, e.g. How to Reduce Your Email Checking to Once A Day Fa 0145b1155a404ba09fc6996fe90586c8.md
    2. I’d like you to save only the latest bit, e.g. 0145b1155a404ba09fc6996fe90586c8. You may keep it as a variable.
    3. Rename the file to this name, e.g. 0145b1155a404ba09fc6996fe90586c8.md
    4. If there’s a directory with the same original name,
      1. rename it too, e.g. 0145b1155a404ba09fc6996fe90586c8
      2. inside the markdown file, find each line with this new shorten name. It would always follow the pattern of the link in markdown syntax. E.g. How%20to%20Reduce%20Your%20Email%20Checking%20to%20Once%20A%20Day%20Fa%200145b1155a404ba09fc6996fe90586c8/untitled, I want you to trim the link to keep only the 0145b1155a404ba09fc6996fe90586c8.md part. So the line would become 0145b1155a404ba09fc6996fe90586c8/untitled.

    The issue with renaming the files is that they contain links that are better to rename too. I don’t know how to automate it.


So I updated the logic, and don’t rename files with their ids. I just rename the files and directories according to its creation time.

  1. Rename the files to dates.

Very bad. Forget this script and write me another one.

I provide you a path that have markdown files and directories.

  1. Check every file in a given path
  2. Find the line that starts with the word Created: , e.g.: Created: December 12, 2016 9:10 AM
  3. Check whether the file has a directory counterpart with the same name (without the .md extension). E.g. example-name directory and example-name.md file.
  4. Rename both directory and the file, follow this pattern: YYYY-mm-DD-HHMM for directory and YYYY-mm-DD-HHMM.md for a markdown file, where YYYY is the year, mm is the month, DD is the day of the month, HH is hours in 24-hr format, MM is minutes. E.g. 2016-12-12-0910. Take the date from Created: .
  5. If there’s the file and directory with that name already, increase minute by one for both file and directory, e.g. 2016-12-12-0911, so the filenames would be unique.
  6. If there’s just a file and no directory with the same name, I’d like to rename the file with the same logic.