A magic number is a sequence of bytes that is used in all files of a certain format, usually at a given position (often at the beginning). Since all files in that particular format have that particular byte sequence in that particular position, and most files in other formats don't have it, the magic number is a way to recognize what format a file is in.
Here, this concept is applied to a filesystem format. For example, an ext2/ext3/ext4 filesystem always has the bytes 0x53 0xEF
at positions 1080–1081. A reiserfs filesystem always has ReIsErFs
starting at position 65588 (or ReIsEr2Fs
, etc., in more recent versions). Other filesystems have similar magic numbers. Filesystem tools check for the presence of the magic number (and possibly other clues) to ensure that you haven't accidentally launched them on data that's organized in a format they can't deal with and could damage. If you change the magic number on a filesystem, ordinary tools are likely to refuse to touch it; repair tools might be more clever and treat a bad magic number as just one of the things that could be broken.
The file
command recognizes files based on their magic numbers. You can run file -s /dev/sda1
to see what it thinks is on the partition /dev/sda1
. Its decisions are based on a database typically found in /etc/magic
or /usr/share/misc/magic
. Specific commands may use different magic numbers to recognize the file formats they can cope with.
On Ubuntu,
apt-get install source file
will pullfile-x.yy/magic/Magdir/filesystems
which contained exactly the information the question (and I) was looking for. – Nick Garvey – 2013-06-12T00:58:34.257Shouldn't that be
file /dev/sda1
? – Bobby – 2013-09-27T10:46:42.653@Bobby No,
file /dev/sda1
will only tell you that this is a device node, it doesn't say anything about the content. You need eitherfile </dev/sda1
orfile -s /dev/sda1
. – Gilles 'SO- stop being evil' – 2013-09-27T11:04:11.797Oh okay, for me
file < /dev/sda1
fails with the help-text from file (missing parameter?), but-s
works great. Thanks. – Bobby – 2013-09-27T11:06:00.9031@Bobby Ah, I see, I forgot one character. It's
file - </dev/sda1
, because you have to tellfile
explicitly to read from stdin. Thanks, I'll fix it. – Gilles 'SO- stop being evil' – 2013-09-27T11:08:57.580