Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am trying to use the command "file" to search though a very large directory I have and hunt down any files that are of pdf, bmp, jpg, xls, doc etc. type. I do not want to do a simple file search I need to do it this way. Some files do not have extensions on them and some extensions might be the wrong ones. so far I have
The problem with this is I get a couple thousand output lines or more that I must search through. Is there anyway to limit the output to say just of pdf type only.
I tried your suggestion but the problem is when I use ..."*.pdf"... It does a search for any files with the *.pdf extension. I cant use this because its looking at the extension instead of the file type.
In other words I need to ignore each and every files extension and only do a search for a specific file type. for example the file might be named
file.tif
when really it is a pdf file and should be file.pdf
So really what I'm looking to do is a search by file type and not extension.
Thanks for trying to help me out though what makes you think that your help is not wanted?
I did some serious digging around for a solution and the command line just doesn't seem to do the trick. The problem comes from the lack of file extensions so you can't just search for *.pdf because " -type d or -type f " refers to directory or file. I couldn't find any way to do a command line search for files by association type.
The good news is that Konqueror does the job very nicely. I took a known file type and removed the extension ( pic.bmp for instance ) then went to Tools / Find File... then to the Contents tab / File type: . I scrolled down to the file type which I was looking for and it was correctly located even without the extension.
That doesn't work if the file is grossly misnamed like naming a text file with a gif extension.
file * | grep -e HTML will list al HTML files in the directory whether or not they have an HTML extension. You could do the same thing with other file types. I don't know enough about bash scripting or awk to write something that would do it automatically.
Cool thanks for all of the great help guys
here is what seems to work I have just tested this out really quick
find /mnt/user storage/ -exec file {} \; | grep -e pdf
I just noticed your last post sharper I will give awk a try. This is something I have never heard of (not that that means anything at all ) when I do a man awk I get
gawk - pattern scanning and processing language
I will post back here in a miniute when my machine is done doing its nightly scheduled dump. Kind of slows things down to a grinding hault .
The problem I had with awk is getting it to look at any files that are in sub-directories in other words I dont see a recursive switch.
I have had some wierd results with doing this
find /mnt/user storage/ -exec file {} \; | awk '{print $2, $1}' | sort > /home/my user name/Desktop/test-awk
I seems that it prints out all of the file names first then does another print out of the actual file type.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.