Questions tagged [file-command]

file - determine file type.

man 1 file

This manual page documents version 5.04 of the file command.
file tests each argument in an attempt to classify it. There are three sets of tests, performed in this order: filesystem tests, magic tests, and language tests. The first test that succeeds causes the file type to be printed.
The type printed will usually contain one of the words text (the file contains only print‐ ing characters and a few common control characters and is probably safe to read on an ASCII terminal), executable (the file contains the result of compiling a program in a form understandable to some UNIX kernel or another), or data meaning anything else (data is usually ‘binary’ or non-printable). Exceptions are well-known file formats (core files, tar archives) that are known to contain binary data. When modifying magic files or the program itself, make sure to preserve these keywords. Users depend on knowing that all the readable files in a directory have the word ‘text’ printed. Don't do as Berkeley did and change ‘shell commands text’ to ‘shell script’.
42 questions
23
votes
5 answers

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 of a file: file sunrise. Example result: sunrise:…
Flux
  • 2,516
  • 4
  • 20
  • 45
21
votes
4 answers

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 output below. Someone suggested to me that the file…
user2543622
  • 347
  • 1
  • 3
  • 8
20
votes
2 answers

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 three sets of tests on the file in question:…
Abdennour TOUMI
  • 902
  • 3
  • 12
  • 24
17
votes
3 answers

Why does "file xxx.src" lead to "cannot open `xxx.src' (No such file or directory)" but has an exit status of 0 (success)?

Why does file xxx.src lead to cannot open `xxx.src' (No such file or directory) but has an exit status of 0 (success)? $ file xxx.src ; echo $? xxx.src: cannot open `xxx.src' (No such file or directory) 0 Note: to compare with ls: $ ls xxx.src ;…
pmor
  • 509
  • 5
  • 11
16
votes
2 answers

How can the dynamic linker/loader itself be dynamically linked as reported by `file`?

Consider the shared object dependencies of /bin/bash, which includes /lib64/ld-linux-x86-64.so.2 (dynamic linker/loader): ldd /bin/bash linux-vdso.so.1 (0x00007fffd0887000) libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6…
Shuzheng
  • 4,023
  • 1
  • 31
  • 71
14
votes
2 answers

How does the file command distinguish text and LaTeX files?

I have a number of files (Jupyter notebooks, .ipynb) which are text files. All of these contain some LaTeX markup. But when I run file, I get: $ file nb_* nb_1.ipynb: ASCII text nb_2.ipynb: ASCII text nb_3.ipynb: ASCII text,…
cheersmate
  • 265
  • 1
  • 8
13
votes
2 answers

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 readable files in a directory have the word…
yegle
  • 1,129
  • 1
  • 8
  • 12
10
votes
3 answers

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 if a file is a sqlite database. When using the…
dmars
  • 113
  • 1
  • 7
10
votes
2 answers

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". Is there a way to discover when this has happened…
Aescula
  • 363
  • 3
  • 7
9
votes
2 answers

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 experiencing the problem with other CSV files. $ file -b --mime…
Jason Swett
  • 203
  • 2
  • 5
8
votes
2 answers

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 Berkley DB file, even if I cut it down to 16…
Nick ODell
  • 2,498
  • 2
  • 20
  • 28
8
votes
3 answers

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://genome.ucsc.edu/FAQ/FAQformat.html#format1 Fasta : …
Pierre
  • 1,713
  • 3
  • 15
  • 21
7
votes
5 answers

Bash script: check if a file is a text file

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: fileExists=10 until [ $fileExists -eq 9 ] do echo…
Powea
  • 73
  • 1
  • 1
  • 4
7
votes
1 answer

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…
Pierre
  • 1,713
  • 3
  • 15
  • 21
6
votes
5 answers

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 would like only to…
Stefan
  • 24,830
  • 40
  • 98
  • 126
1
2 3