DaemonForums  

Go Back   DaemonForums > Other Operating Systems > Other BSD and UNIX/UNIX-like

Other BSD and UNIX/UNIX-like Any other flavour of BSD or UNIX that does not have a section of its own.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 21st March 2013
daemonfowl daemonfowl is offline
bsdstudent
 
Join Date: Jan 2012
Location: DaemonLand
Posts: 834
Thanked 0 Times in 0 Posts
Default any unix utility that determines the right extension of a file ?

Hi everyone !


Suppose you've got a 'extension-less' file and you'd want to a handy tool to determine the right extension of that file ..

Does such a tool exist in Unix Land ?

Regards.

Last edited by daemonfowl; 21st March 2013 at 12:57 AM.
Reply With Quote
  #2   (View Single Post)  
Old 21st March 2013
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 3,435
Thanked 214 Times in 189 Posts
Default

"Extension" has no meaning for Unix or Unix-like systems. There are some applications --- such as compilers -- that may arbitrarily choose to use them.

See the file(1) man page. This is the utility you seek.

Last edited by jggimi; 21st March 2013 at 01:33 AM. Reason: clarity
Reply With Quote
  #3   (View Single Post)  
Old 21st March 2013
daemonfowl daemonfowl is offline
bsdstudent
 
Join Date: Jan 2012
Location: DaemonLand
Posts: 834
Thanked 0 Times in 0 Posts
Default

Hi teacher jggimi and thanks for your reply !
Yes, in Unix everything is a file .. and yet I need to be able to decide about such files .. before sending them to a target OS : windoze.
Reply With Quote
  #4   (View Single Post)  
Old 21st March 2013
Beastie Beastie is offline
Daemonology student
 
Join Date: Jan 2009
Location: /dev/earth0
Posts: 267
Thanked 23 Times in 23 Posts
Default

Quote:
Originally Posted by daemonfowl View Post
Hi teacher jggimi and thanks for your reply !
Yes, in Unix everything is a file .. and yet I need to be able to decide about such files .. before sending them to a target OS : windoze.
I'm not sure you've understood jggimi's reply (sorry if you did), but he was literally suggesting you use the file utility:
% file testfile
or
% file *
__________________
May the source be with you!
Reply With Quote
  #5   (View Single Post)  
Old 21st March 2013
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,118
Thanked 182 Times in 149 Posts
Default

Code:
$ file Downloads/*iso
Downloads/FreeBSD-9.1-RELEASE-i386-disc1.iso: ISO 9660 CD-ROM
filesystem data 'FREEBSD_INSTALL' (bootable)

$ file $(which s2p)
/usr/bin/s2p: a /usr/bin/perl script text executable

$ file /bin/ls
/bin/ls: ELF 64-bit LSB executable, x86-64, version 1, for OpenBSD,
statically linked, stripped

$ file /bsd    
/bsd: ELF 64-bit LSB executable, x86-64, version 1, statically linked,
not stripped

$ file pf-redir
pf-redir: ASCII text

$ file tip.record
tip.record: ASCII English text, with very long lines, with CRLF,
CR, LF line terminators, with escape sequences, with overstriking

$ file SNPMapping.tab
SNPMapping.tab: Little-endian UTF-16 Unicode character data, with CR line
terminators
See file(1)
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
  #6   (View Single Post)  
Old 21st March 2013
daemonfowl daemonfowl is offline
bsdstudent
 
Join Date: Jan 2012
Location: DaemonLand
Posts: 834
Thanked 0 Times in 0 Posts
Default

Thank you so much. That's just what I needed !
Reply With Quote
  #7   (View Single Post)  
Old 21st March 2013
thirdm thirdm is offline
Package Pilot
 
Join Date: May 2009
Posts: 180
Thanked 3 Times in 3 Posts
Default

You would almost certainly need to customize the output to your needs, but there seems to be a CPAN module that can map file mimeinfo to typical (windows?) file extensions: http://search.cpan.org/~pardus/File-...le/MimeInfo.pm

Quote:
extensions($mimetype)

In list context, returns the list of filename extensions that map to the given mimetype. In scalar context, returns the first extension that is found in the database for this mimetype.
Reply With Quote
  #8   (View Single Post)  
Old 22nd March 2013
daemonfowl daemonfowl is offline
bsdstudent
 
Join Date: Jan 2012
Location: DaemonLand
Posts: 834
Thanked 0 Times in 0 Posts
Default

Thanks thirdm !

Code:
Running Build install
Building File-MimeInfo
Installing /usr/local/man/man1/mimeopen.1
Installing /usr/local/man/man1/mimetype.1
Installing /usr/local/libdata/perl5/site_perl/File/MimeInfo.pm
Installing /usr/local/libdata/perl5/site_perl/File/MimeInfo/Rox.pm
Installing /usr/local/libdata/perl5/site_perl/File/MimeInfo/Applications.pm
Installing /usr/local/libdata/perl5/site_perl/File/MimeInfo/Magic.pm
Installing /usr/local/libdata/perl5/site_perl/File/MimeInfo/Cookbook.pod
Installing /usr/local/man/man3p/File::MimeInfo.3p
Installing /usr/local/man/man3p/File::MimeInfo::Cookbook.3p
Installing /usr/local/man/man3p/File::MimeInfo::Rox.3p
Installing /usr/local/man/man3p/File::MimeInfo::Magic.3p
Installing /usr/local/man/man3p/File::MimeInfo::Applications.3p
Installing /usr/local/bin/mimeopen
Installing /usr/local/bin/mimetype
  PARDUS/File-MimeInfo/File-MimeInfo-0.16.tar.gz
  ./Build install  -- OK
mimetype works perfectly ..

.iso mimetype seems different though :
When I mv x.iso to x , its size gets smaller and mimetype fails to determine its id -so to speak- it says : text/plain instead of x-cd-image.
The file command however seems smarter , same output for ipxe which is actually ipxe.iso :
Code:
 file ipxe
ipx: ISO 9660 CD-ROM filesystem data 'CDROM                          ' (bootable)
Reply With Quote
  #9   (View Single Post)  
Old 22nd March 2013
jb_daefo jb_daefo is offline
Package Pilot
 
Join Date: May 2008
Posts: 196
Thanked 5 Times in 5 Posts
Default

Code:
for f in $(find . type f ); do (mimetype "$f" | tee -a /tmp/files.mimetype); done
Works great! And one can grep the resulting file for "shellscript" to find scripts among a slew of html and jpg etc.. (Among other uses...)
__________________
using /LOOKAT/ with /var/db/pkg files and portmaster/aliases/pipes/find/grep to meteorically speedup port upgrades/installs...
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to install php5-gd extension schh OpenBSD General 6 16th June 2011 06:57 PM
.wav file playing very fast on unix, fine on win gosha General software and network 16 2nd June 2009 02:37 PM
USB extension cable: bad? IdOp General Hardware 3 24th January 2009 08:41 PM
Remote backup utility stukov General software and network 18 13th June 2008 08:42 PM
php cli and imagick extension mtx FreeBSD General 5 22nd May 2008 08:51 PM


All times are GMT. The time now is 07:29 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick