Skip to content

Instantly share code, notes, and snippets.

@zach-klippenstein
Created October 6, 2009 01:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zach-klippenstein/202673 to your computer and use it in GitHub Desktop.
Save zach-klippenstein/202673 to your computer and use it in GitHub Desktop.
Prints out a bunch of information about all files in the current directory and subdirectories, recursively (see comment header for more info)
#!/bin/bash
# by Zachary Klippenstein
#
# Prints out a bunch of information about all files in the current
# directory and subdirectories, recursively.
# Info includes:
# - filename
# - file type (as given by 'file' command)
# - file contents (prefixed by filename and line number in file, and for binary files, result of 'strings')
# Like cat, but prints the name of the file before.
# Reads filenames from stdin
function tagcat()
{
while read filename; do
(text="`file \"$filename\" | grep text`"
if [ "$text" ]; then
cat "$filename"
else
strings "$filename"
fi) |
(linenum=0
while read line; do
linenum=$((linenum + 1))
echo "${filename}: ${linenum}) ${line}"
done)
done
}
find
find -exec file \{\} \; 2>/dev/null
find -not -type d 2>/dev/null | tagcat 2>/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment