Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [file-command]

file - determine file type.

9
votes
3answers
2k views

How to find files by file type?

I know I can find files using find: find . -type f -name 'sunrise'. Example result: ./sunrise ./events/sunrise ./astronomy/sunrise ./schedule/sunrise I also know that I can determine the file type ...
0
votes
1answer
82 views

Ubuntu 18.04 think C/C++ source code file is plain text

When I try to create a C/C++ source file touch test.cpp Usually it will generate a file which type is C source code file. But today I got a plain text file. And I write a simple program in it like: ...
2
votes
1answer
53 views

Why does linux recognise a C# .cs file as a C++ source file?

I used the file command on a c# source file, and linux thought it was a c++ file. What is the reason for this?
0
votes
5answers
85 views

How to open a file based on the output of the `file` command

So I have a directory where I wish to open the only file in that directory that is human readable. I use file * to print the type of each file, and one file shows as ASCII-text. How can I redirect ...
4
votes
1answer
714 views

how can I read a number with file (magic)?

I would like to write the format of a drawing with "file drawing" Files start like: CAD A1 mm (Blank after A1) or: CAD A00 m (Blank after "m") I tried somethings like in the file magic: 0 ...
1
vote
1answer
75 views

file command does not recognize perl module

The file command (Debian Jessie) in does not recognize some Perl modules. For example: /usr/share/perl5/XML/SAX.pm (from libxml-sax-perl) gives: $ file /usr/share/perl5/XML/SAX.pm /usr/share/perl5/...
1
vote
1answer
598 views

file command output for a non-ASCII text file in AIX and Linux [closed]

I am getting different output while using file command in AIX vs Linux. File contents : D|P_APAC_PH_PHINGTF00240_20150731031225|APAC|PH|NN (L) SPEK DYWIDENDOWYCH RYNKÓW WSCHODZCYCH||4|20130308|PHN|...
1
vote
2answers
180 views

/usr/bin/file exit status always 0

I'm trying to use /usr/bin/file to detect file types in a program but also would like it to report if the file does not exist. However the command always returns exit status 0. Besides grepping the ...
1
vote
2answers
1k views

how to move all files from a pipe into a directory ?

I performed a file-command on all elements in my Desktop directory: ~/Desktop > file * then I grepped all the lines who have the string "image" in the description: ~/Desktop > file * | grep "...
3
votes
1answer
129 views

file/libmagic: What is the “ID3 length”?

The man pages of the file command/libmagic are talking about a datatype called "ID3 length". The only explanation i found was: A 32-bit ID3 length So what is this for a type ? Is it related to the ...
1
vote
1answer
161 views

libmagic (file) database “use” and “clear” type

I am currently writing a parser for the libmagic database (used by the file command) and i don't found any information on the 'use' and 'clear' type (second column in the magic file). Can someone ...
8
votes
2answers
502 views

How did file identify this particular file?

I'm running file against a wallet.dat file (A file that Bitcoin keeps its private keys in) and even though there doesn't seem to be any identifiable header or string, file can still tell that it's a ...
3
votes
5answers
9k views

Bash script: check if a file is a text file [closed]

I am writing a menu based bash script, one of the menu options is to send an email with a text file attachment. I am having trouble with checking if my file is a text file. Here is what I have: ...
3
votes
2answers
3k views

How to list files on terminal so that we can see the file types such executable, ascii etc?

I have been trying to list files in directory using ls and passing it different options. Does it have the ability to list types of files as well ? I want to know which ones are executable , ...
4
votes
3answers
3k views

How to list only JPEG files from root below using the command line?

I am searching for a method to find only JPEG files/ With my limited knowledge of Linux I came to this point: list all paths that exist from root below with find / pipe the result into next command ...
4
votes
2answers
4k views

file command apparently returning wrong MIME type

Why doesn't the following return text/csv? $ echo 'foo,bar\nbaz,quux' > temp.csv;file -b --mime temp.csv text/plain; charset=us-ascii I used this example for extra clarity but I'm also ...
1
vote
3answers
2k views

Find file by magic pattern maching

There is a bash command file(1) which outputs a file's contents type according to the matching pattern definitions in the /etc/magic and /usr/share/misc/magic. Is there a way to use these pattern ...
3
votes
1answer
13k views

How to check the file type in a script

I want to do a loop for all the images in a directory. The images doesn't have extension so I have to read the first bytes of the image to know its type. The loop should end up being something like. ...
0
votes
2answers
7k views

Check if a file is a text file in bash

I am trying to make a check to see if the file being attached to the email is a text file, and if it is not it returns an error. However during testing, I provide a valid text.txt and it returns the "...
8
votes
2answers
1k views

Finding a file type assuming wrong extension

I have an image archive I keep up. Sometimes, the sites I pull them from reformat the file while keeping the extension the same, most often making PNG images into JPG's that are still named ".png". ...
7
votes
1answer
244 views

file(1) and magic(5) : prioritizing a result

My question follows that one: file(1) and magic(5) : describing other formats . I want to describe a FASTA sequence ( http://en.wikipedia.org/wiki/FASTA_format) It could be a DNA sequence (with only ...
8
votes
3answers
1k views

file(1) and magic(5) : describing other formats

Can I use file and magic ( http://linux.die.net/man/5/magic ) to override the description of some other known formats ? for example, I would like to describe the following formats: BED: http://...
1
vote
2answers
1k views

File command database and identifying text files

Please let me know if below two statements are correct or not: Folder /usr/share/mime/magic has a database/table that will give me what are the current possible file formats (outputs that I can get ...
15
votes
4answers
16k views

Linux file command classifying files

I need to recognize type of data contained in random files. I am new to Linux. I am planning to use the file command to understand what type of data a file has. I tried that command and got the ...
3
votes
2answers
179 views

Test for a particular file format

This is a followup to Normal looking text file, detected by file as ASCII Pascal program text It seems file can't be trusted all the time. It seems possible that a particular file may be detected ...
20
votes
2answers
2k views

What does “magic tests” mean for the file command?

I was reading about the file command and I came across something I don't quite understand: file is designed to determine the kind of file being queried.... file accomplishes this by performing ...
1
vote
2answers
834 views

`file` doesn’t show proper mime-type for .m2ts files

I need to define mime type of various video files and I got a problem with .m2ts files. Before I stumbled on this, I used file utility with -iL keys and parsed the output with sed. Today I found that ...
11
votes
2answers
404 views

What's the story behind command file's suggestion?

While I'm reading file(1) I noticed this in the man page (emphasis mine): When adding local definitions to /etc/magic, make sure to preserve these keywords. Users depend on knowing that all the ...
7
votes
3answers
5k views

Fast way to determine if a file is a SQLite database

I am looking for a way to determine file types in a folder with thousands of files. File names do not reveal much and have no extension, but are different types. Specifically, I am trying to determine ...
2
votes
1answer
1k views

Detect file-type with the help of magic-file and rename file-suffix accordingly

I have a folder (the iPhone Backup) with various files without a suffix. I want to run a batch process over these files, which detects each file's file-type (with the help of the magic-file database (...
5
votes
2answers
2k views

More sophisticated file command for deep inspection?

Sometimes it seems that the standard file command (5.04 on my Ubuntu system) is not sophisticated enough (or I am just using it wrong, which could well be). For example when I run it on an .exe file, ...
2
votes
2answers
2k views

How to find human-readable information about file types recognized by `file`?

Searching, googling, I could not find any information about file types recognized by file. For example, an *.mp4 file is identified as "ISO Media" (while being able to play with VLC normally). This ...
6
votes
1answer
316 views

What could cause strange behavior in file(1) command?

What could cause file(1) command to output application/msword application/msword (yes, twice in a row) as the mime type for some of the .doc files? Normally it prints just application/msword. If run ...
2
votes
1answer
144 views

How can I create a file that just contains a binary number?

I would like to create a file that just contains a binary number. I think that touch can be used to create an empty file, but is there any way I can fill it with a binary number e.g. 10 (ten)? And how ...
6
votes
5answers
9k views

How to find image files by content

I have a list of files and I need to find all the image-files from that list. For example, if my list contained the following: pidgin.tar.gz photo01.jpg picture01 screenshot.gif invoice.pdf Then I ...