Date Tags zsh / shell (< 1 min read)

I just ran:

find * -type f -exec echo "{}" \; -exec awk "NR==26" {} \;

Which I adapted from this StackOverflow post and, tldr, searches all files in my current directory (and subdirectories) and tells me what's written on line 26.

Or, parsing it out:

  • find: "Find files or directories under the given directory tree, recursively." ( - tldr)
  • *: Anything in the current directory.
  • -type f: A file (not a directory).
  • -exec: A flag in find which will run a shell command. If you include {} in that shell command, it will replace it with the "found" filename (or directory).
  • echo: Print to stdout.
  • "{}": The current filename.
  • \;: End of that command.
  • -exec: Yo, you can chain these guys!
  • awk: "A versatile programming language for working on files." ( - tldr) AKA, magic.
  • "NR==26": Magic syntax. Found this via StackOverflow. Line number 26.
  • {}: The current filename (still coming from the find command).
  • \;: The end.

It outputs something like:

file1.txt
README.md
some_subdirectory/file2.txt
          some random text on line 26
some_subdirectory/file3.txt

.some_config_file
  enabled: true

Cool!