Zettelkasten Forum


Search for untagged files

Sorry for what may be a question with an obvious answer, but I've searched everywhere and can't find the answer: What is the appropriate search query to return a list of untagged files? Thanks.

Comments

  • @jerrybrito To find notes that do not have tags in them, use the search term NOT # in the Omnibar.

    Will Simpson
    “Read Poetry, Listen to Good Music, and Get Exercise”
    kestrelcreek.com

  • Thanks. I had tried that, but that has the effect of omitting all files that a "#" in them. So, if I have used '#" to denote

    <

    h1>, then the file won't be shown in the results even if it has no #tag. I'm surprised I may have found a corner case. :)

  • @jerrybrito You are correct. I just took a quick look when I offered my first suggestion and all the notes in my archive list had no tags. On closer examination, like you, I see it doesn't show and notes with no tags but where I have included a "#" in the note somewhere. I think I have a solution but the forum software garbled your prior message and I can't see what you "have used '#" to denote". Maybe a screenshot or encapsulating the text in a code block would fool the forum software into the proper display.

    Will Simpson
    “Read Poetry, Listen to Good Music, and Get Exercise”
    kestrelcreek.com

  • @jerrybrito Try this.

    In Terminal
    cd "~/Your Zettelkasten/Directory/"
    then run
    egrep -L "#\w" -- * | sed -E -e 's/.[^.]*$//' -e 's!^([0-9]+)[[:space:]-]+(.+)!\2 [[\1]]!'> "NO TAGS.md"

    Explanation

    egrep -L "#\w" -- *
    find all files without a "#" followed immediately by a word character ignoring all other uses of the "#". You can try this portion of the command all by itself and check the results. The rest of the command just makes it easier to navigate.

    sed -E -e 's/.[^.]*$//' -e 's!^([0-9]+)[[:space:]-]+(.+)!\2 [[\1]]!'
    Reformats the file names "201811091435 Stop while ahead.md"
    To "Stop while ahead [[201811091435]]"

    > "NO TAGS.md"
    Output the results to a new note in your Zettelkasten with links to all the files with no tags titled NO TAGS.

    Give this a try and let me know the results. I got 353 notes without tags?! (I checked a couple of dozen and they had the "#" used in the body but no tags.

    Screenshot of a portion of my NO TAGS note.

    Will Simpson
    “Read Poetry, Listen to Good Music, and Get Exercise”
    kestrelcreek.com

  • @Will I love these automatically generated maintenance notes :) That's so in line with what I imagined to emerge from plain text storage & scripting & smart people coming together.

    Author at Zettelkasten.de • https://christiantietze.de/

  • egrep -L "#\w" -- * may run into a few problems. Replace it with the following:

    find . -type f -name '*.md' -print0 | xargs -0 egrep -L '#\w'
    
  • @bvs said:

    find . -type f -name '*.md' -print0 | xargs -0 egrep -L '#\w'
    

    Thanks for the suggestion, works great for searching subfolders too.

    The only caveat is that the output of the find command could not be piped into sed -E -e 's/.[^.]*$//' -e 's!^([0-9]+)[[:space:]-]+(.+)!\2 [[\1]]!' without some modifications to the sed script in order to get the desired output. Not impossible but the find command can't be just substituted as is.

    What problems did you run into?

    Will Simpson
    “Read Poetry, Listen to Good Music, and Get Exercise”
    kestrelcreek.com

  • bvsbvs
    edited May 2020
    find . -type f -name '*.md' -print0 | xargs -0 egrep -L '#\w' | sed 's!^\./!!' | \
    grep -v '^\.' | sed -E -e 's!^([0-9]+)[[:space:]-]+(.+)!\2 [[\1]]!
    

    The first sed strips off leading ./ while the grep removes files whose names start with a . and last sed does the conversion as before. I don't know what you'd want for files in subdirs but they'd show up something like this: "Stop while ahead [[subdir/201811091435]]".

    What problems did you run into?

    I was thinking of what happens when there are 70,000 files :-) You'd run into the MAX_ARGS count limit.

  • edited May 2020

    @bvs Thanks for your input. I made some tweaks to the command and redirecting the output so it becomes a note in the archive that can be used to navigate to the notes without tags.

    find ./ -type f -depth 1 -name '*.md' -print0 | xargs -0 egrep -L '#\w' | sed 's!^\./!!'| sort -r | sed -E -e 's!^\/([0-9]+)[[:space:]-]+(.+)\..*!\2 [[\1]]!' > "202005132034 ★ Zettels without Tags.md"

    Added -depth 1 option to limit results to the current directory.
    Added sort -r to put the newest zettels at the top of the list.
    Deleted the second grep
    Modified the last sed command so as to remove the leading ./ in the names
    Modified the last sed command so the file extension is lopped off.
    Added a redirect of the output to a note with links to every zettel without a tag.

    @bvs said:
    I was thinking of what happens when there are 70,000 files :-) You'd run into the MAX_ARGS count limit.

    I hadn't taken into account the 70,000 note limit. Glad you pointed this error out. I have to be careful cuz at my current rate I'll be at this limit on August 13, 2103, and it will be here before we know it.

    In all seriousness, thanks for your input. Let me know if you see other areas needing correction or for improvement.

    I almost forgot a screenshot of the results.

    Will Simpson
    “Read Poetry, Listen to Good Music, and Get Exercise”
    kestrelcreek.com

  • Mind just blown!

    I took the created file "202005132034 ★ Zettels without Tags" and ran it through the Keyboard Maestro macro that @ctietze got me working on for reviewing structure notes. The macro ultimately puts all the notes referenced in the target note on the note list for easy browsing. This way a review can happen quickly moving up and down in the note list with the arrow keys without mousing each link and using the back function.

    I was able to populate the note list with all the notes that did not have tags and at speed surf from note to note. How else could this be used?

    Screenshot - all the notes in the note list do not have tags. 155 Notes without tags.

    Will Simpson
    “Read Poetry, Listen to Good Music, and Get Exercise”
    kestrelcreek.com

  • @Will said:
    @bvs Thanks for your input. I made some tweaks to the command and redirecting the output so it becomes a note in the archive that can be used to navigate to the notes without tags.

    find ./ -type f -depth 1 -name '*.md' -print0 | xargs -0 egrep -L '#\w' | sed 's!^\./!!'| sort -r | sed -E -e 's!^\/([0-9]+)[[:space:]-]+(.+)\..*!\2 [[\1]]!' > "202005132034 ★ Zettels without Tags.md"

    Added -depth 1 option to limit results to the current directory.
    Added sort -r to put the newest zettels at the top of the list.
    Deleted the second grep
    Modified the last sed command so as to remove the leading ./ in the names
    Modified the last sed command so the file extension is lopped off.
    Added a redirect of the output to a note with links to every zettel without a tag.

    Looks good!

    @bvs said:
    I was thinking of what happens when there are 70,000 files :-) You'd run into the MAX_ARGS count limit.

    [Correction: meant to write ARG_MAX.]

    I hadn't taken into account the 70,000 note limit. Glad you pointed this error out. I have to be careful cuz at my current rate I'll be at this limit on August 13, 2103, and it will be here before we know it.

    :smiley: Well... you'd run into the ARG_MAX limit much earlier. It could be as low as 4096 though typically it is much higher these days (256K -- which means you can specify 8K files in the command line if the average filename length is 32 bytes or so).

    In all seriousness, thanks for your input. Let me know if you see other areas needing correction or for improvement.

    You're welcome!

Sign In or Register to comment.