Created
October 6, 2009 01:25
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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