LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 10-15-2009, 06:00 AM   #1
forkbeard
LQ Newbie
 
Registered: Oct 2009
Location: Sheffield U.K
Posts: 7

Rep: Reputation: 0
Command For Finding Specific File Types?


Hi,

Can someone tell me if there is a command i can use to find specific file types? say if i want to find all the jpg's in my home folder, but they don't have the .jpg extension in the name, how would i do it? Or can i set some kind of size parameter to find them? The ones i want are all from my digicam and roughly the same size.

Thanks,

FB.
 
Old 10-15-2009, 06:12 AM   #2
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
You are in luck, linux cares not what the file extension is anyway.

Man pages
http://linux.die.net/man/1/file
http://linux.die.net/man/1/mimetype

Howtos
http://www.cyberciti.biz/faq/linuxun...ine-file-type/
http://www.foogazi.com/2007/10/26/qu...ypes-on-linux/

example
Code:
$ file Screenshot
Screenshot: PNG image data, 1024 x 718, 8-bit/color RGBA, non-interlaced
$ file photo
photo: JPEG image data, JFIF standard 1.01
see?

All the files in a directory?

for file in dir -d *`; do file $file; done

Last edited by Simon Bridge; 10-15-2009 at 06:22 AM.
 
Old 10-15-2009, 06:22 AM   #3
forkbeard
LQ Newbie
 
Registered: Oct 2009
Location: Sheffield U.K
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks for the reply/links, although I think I should have phrased it differently! What I'm after is not trying to find out what the file type is of certain files, but finding files of a certain file type. For example, using find or ls to locate all jpg files (but ones that don't have .jpg in the name).
 
Old 10-15-2009, 06:26 AM   #4
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,629

Rep: Reputation: Disabled
Yes you can use find to locate all the file with jpg in their name.

find / -name *.jpg
 
Old 10-15-2009, 06:27 AM   #5
forkbeard
LQ Newbie
 
Registered: Oct 2009
Location: Sheffield U.K
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by linuxlover.chaitanya View Post
Yes you can use find to locate all the file with jpg in their name.

find / -name *.jpg
But how would you find jpg files that didn't have the extension in the name? If they were all just named "wedding1" instead of "wedding1.jpg".

Last edited by forkbeard; 10-15-2009 at 06:42 AM.
 
Old 10-15-2009, 06:49 AM   #6
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,528

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
You could try this

Code:
for i in `ls -R /home/user/`; do file $i | grep JPEG ;done
 
Old 10-15-2009, 07:30 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,294

Rep: Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358
For completeness I'd use the -i switch for grep, just in case.
 
Old 10-16-2009, 12:02 AM   #8
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
Quote:
Originally Posted by forkbeard View Post
Thanks for the reply/links, although I think I should have phrased it differently! What I'm after is not trying to find out what the file type is of certain files, but finding files of a certain file type. For example, using find or ls to locate all jpg files (but ones that don't have .jpg in the name).
Yes, I understood that. All I did was provide you with the important link.

The solution you want is a script which uses the file command to locate all the files of a certain type. You may also want to extend your search to subdirectories.

I suspect you'd also like to operate on the files - add .jpg to the end of their filenames or move them to a particular folder, or run some imagemagick operations for some reason.

You can encorporate these things into your script.
 
  


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
ls -- changing color of a substring for specific file types linav Linux - General 4 06-20-2008 12:16 PM
Keep specific file types, delete the rest ? jchambers Programming 5 11-26-2007 06:25 PM
Find command - multiple file types mrclisdue Linux - General 4 07-03-2006 03:48 AM
Finding a specific file j_carmona Linux - Newbie 12 05-02-2005 07:42 PM
vsftpd disallow specific file types from being uploaded GUIPenguin Linux - General 2 04-08-2005 10:04 AM


All times are GMT -5. The time now is 11:27 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration