CommandLineFu: Basic Filetype Report

A little more find magic:

find . -type f -printf '%d|%k|%f|' -exec file -F"|" -pi '{}' \;


find .

Start searching within the working directory.

-type f

Return only files, not directories

-printf '%d|%k|%f|'

Output tree depth, then a pipe, file size in bytes, then a pipe, then the filename without the leading directories, and a pipe.

-exec file -F"|" -pi

Execute “file” command on file found using a pipe delimiter (-F”|”)instead of the default “:” colon, additionally do not change last access times (-p), and output the file type in mime format (-i).

for dir in */; do a=${dir%%,*} ; find "$dir" -type f -printf '%d|%k|%f|' -exec file -F'|' -pi '{}' \; > "a$"_LIST.TXT & done ; wait

I use the above FOR loop when I have many folders that I need to generate a report for.

In this case all of my top level folders are named after a person “Last, First”, so I create a variable cutting everything after the first comma. I use that variable (the last name) to create an empty text file.  The results of the find command are appended to this text file.

The only obvious pitfall is if two folders have the same value before the comma.  Or two different people have the same last name.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s