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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
05-24-2011, 06:50 AM
|
#1
|
|
LQ Newbie
Registered: May 2011
Posts: 9
Rep: 
|
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.
|
|
|
|
05-24-2011, 07:00 AM
|
#2
|
|
Member
Registered: Jun 2005
Location: England
Distribution: SLED, openSUSE
Posts: 982
Rep: 
|
Look at the file command.
|
|
|
|
05-24-2011, 07:00 AM
|
#3
|
|
Senior Member
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,024
Rep: 
|
|
|
|
|
05-24-2011, 08:03 AM
|
#4
|
|
LQ Newbie
Registered: May 2011
Posts: 9
Original Poster
Rep: 
|
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.
|
|
|
|
05-24-2011, 08:20 AM
|
#5
|
|
Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 6,386
|
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.
|
|
|
|
05-24-2011, 08:22 AM
|
#6
|
|
Member
Registered: Jun 2005
Location: England
Distribution: SLED, openSUSE
Posts: 982
Rep: 
|
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?
|
|
|
|
05-24-2011, 09:29 AM
|
#7
|
|
Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 6,386
|
I get most of your second set of information and version is 5.03
|
|
|
|
05-24-2011, 09:42 AM
|
#8
|
|
Member
Registered: Jun 2005
Location: England
Distribution: SLED, openSUSE
Posts: 982
Rep: 
|
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.
|
|
|
|
05-24-2011, 10:29 AM
|
#9
|
|
Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 6,386
|
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.
|
|
|
|
05-24-2011, 11:48 PM
|
#10
|
|
LQ Newbie
Registered: May 2011
Posts: 9
Original Poster
Rep: 
|
Getting mimetype from the attached file
Thanks All,
I got the Mimetype of the file using
file --mime-type filename
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 10:02 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|