[Cialug] List file types in a directory

Josh More morej at alliancetechnologies.net
Thu Mar 8 19:24:40 CST 2007


Nathan beat me to it, but in my opinon, you're approaching this the
wrong way.

Try something like "file *"

Then, if you need to do further processing, you can do cuts on ':' or
spaces, use paste, and sort to manipulate the listings.
It would be far safer and more accurate this way.


 

-Josh More, RHCE, CISSP, NCLP 
 morej at alliancetechnologies.net 
 515-245-7701


>>> "Nathan Stien" <nathanism at gmail.com> 03/08/07 4:35 PM >>> 
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
_______________________________________________
Cialug mailing list
Cialug at cialug.org
http://cialug.org/mailman/listinfo/cialug



More information about the Cialug mailing list