[Cialug] List file types in a directory
Nathan Stien
nathanism at gmail.com
Thu Mar 8 16:35:19 CST 2007
On 3/8/07, Daniel Juliano <dan at danandlaurajuliano.com> wrote:
> So, how would I get a list of file types for all files in a directory?
> Let's say I've got the following:
> test1.txt
> test2.txt
> test3.jpg
>
> I'd like something similar to:
> .txt
> .jpg
>
I'll go ahead and play the pedant here. I would caution you that on
*nix, there is not a 1:1 mapping between extensions and file types.
The obvious examples would be that there are many files that have no
extension but very different types ("Makefile", /bin/sh, /vmlinuz,
etc.). Likewise, the same file type could be in files with different
extensions. E.g., foo.htm and bar.html could both be of type
text/html.
The mappings between types and extensions, such as they are, are
usually represented in /etc/mime.types.
This may or may not affect you, depending on what you're trying to do.
--
Nathan P. Stien
Consulting Engineer / Software Developer
Embedded Systems Electronics and Software
http://linkedin.com/in/nathanstien
Mobile: 309.241.2581
More information about the Cialug
mailing list