LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 05-24-2011, 06:50 AM   #1
swathikumar
LQ Newbie
 
Registered: May 2011
Posts: 9

Rep: Reputation: Disabled
Getting Content-type/Mime type of the file using shellscript


Hi All,
I am copying the file form one directory to another directory using shellscript.
Here i want to get the Mimetype/Content-type of the file.

How to i can get the MimeType.
Can any one help me on this.
 
Old 05-24-2011, 07:00 AM   #2
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: SLED, openSUSE
Posts: 1,009

Rep: Reputation: 171Reputation: 171
Look at the file command.
 
Old 05-24-2011, 07:00 AM   #3
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,110

Rep: Reputation: 218Reputation: 218Reputation: 218
Code:
file -i filename
 
Old 05-24-2011, 08:03 AM   #4
swathikumar
LQ Newbie
 
Registered: May 2011
Posts: 9

Original Poster
Rep: Reputation: Disabled
Getting mimetype from the attached file

Hi All,
If i copy a one ms-word file the Mimetype should be application/msword

How to i can get this Mimetype using shell script.

I tried to using
file -i filename it is giving "regular file" but i want actual content type.
 
Old 05-24-2011, 08:20 AM   #5
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,411

Rep: Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874
Well I am not sure why linux would necessarily know that mime type as it is not native nor an installed application, but the closest with file seems to be:
Code:
file --mime-type file.doc
file.doc: application/vnd.ms-office
man to the rescue again.
 
Old 05-24-2011, 08:22 AM   #6
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: SLED, openSUSE
Posts: 1,009

Rep: Reputation: 171Reputation: 171
Hmmm. I don't get application/msword

Code:
me@mine:~> file  ForeignLanguageSupport.doc
ForeignLanguageSupport.doc: Microsoft Office Document
me@mine:~> file -i ForeignLanguageSupport.doc
ForeignLanguageSupport.doc: application/octet-stream
me@mine:~> file --version
file-4.24
magic file from /etc/magic:/usr/share/misc/magic
me@mine:~> cat /etc/novell-release 
SUSE Linux Enterprise Desktop 11 (i586)
VERSION = 11
PATCHLEVEL = 1
If I build the very latest version from http://www.darwinsys.com/file/ I get something rather different

Code:
me@mine:~> /tmp/blah/bin/file  ForeignLanguageSupport.doc
ForeignLanguageSupport.doc: Composite Document File V2 Document, Little Endian, Os: Windows, Version 1.0, Code page: -535, Revision Number: 0, Total Editing Time: -584753d+00:00:00, Create Time/Date: Tue Jun 17 09:19:03 2008
me@mine:~> /tmp/blah/bin/file -i ForeignLanguageSupport.doc
ForeignLanguageSupport.doc: application/vnd.ms-office; charset=binary
me@mine:~> /tmp/blah/bin/file --version
file-5.07
magic file from /tmp/blah/share/misc/magic

Don't know why it's so different. What version of file are you using and on what version of Linux?

Code:
$ file --version
 
Old 05-24-2011, 09:29 AM   #7
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,411

Rep: Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874
I get most of your second set of information and version is 5.03
 
Old 05-24-2011, 09:42 AM   #8
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: SLED, openSUSE
Posts: 1,009

Rep: Reputation: 171Reputation: 171
I should perhaps clarify that my question "What version of file are you using and on what version of Linux?" was aimed at the OP(*). I was evidently typing at the same time as grail and their post was shorter so appeared two minutes before mine



(*) Who has only two posts and is posting from a machine running 'macos' according to the icon on their posts, which makes me wonder if they're under the impression that Mac OS X is a version of Linux. Their posting from a Mac doesn't mean they're not using Linux on another machine of course. I sometimes post from a Mac.
 
Old 05-24-2011, 10:29 AM   #9
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,411

Rep: Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874
That's fine ... just thought I would add mine to as the output was slightly different

(*) And MAC can probably be considered a derivation seeing it is just a really fancy wm on darwin anyway (duck)

Last edited by grail; 05-24-2011 at 10:30 AM.
 
Old 05-24-2011, 11:48 PM   #10
swathikumar
LQ Newbie
 
Registered: May 2011
Posts: 9

Original Poster
Rep: Reputation: Disabled
Getting mimetype from the attached file

Thanks All,

I got the Mimetype of the file using
file --mime-type filename
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get file icon from extension, file type, or mime-type Guitarist88 Programming 3 04-21-2008 10:58 AM
Warning ___ specifies undefined mime type/service type mbvpixies78 Linux - Software 0 12-29-2007 10:25 PM
How do you get the mime type of a file using C++ in KDE? ManuPeng Programming 2 04-02-2007 03:06 PM
Cannot not run executable jar file after set content type for download antony_csf Programming 1 12-08-2004 12:22 AM
Determining MIME Type of a File Jose Muņiz Linux - General 2 08-16-2004 01:44 AM


All times are GMT -5. The time now is 03:14 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration