Show file system types linux

10 basic & powerful commands to check file system type in Linux/Unix

Any operating system must be able to access and manage files on storage devices; however, the manner in which the files are organized on a storage device is actually set by the underlying filesystem.With Linux and Unix there are various filesystem types, so in this article I will share multiple commands and methods to check file system type in Linux and Unix.

Before we try to determine and check file system type, we must be familiar with the term «File System».

What is a FileSystem?

As you probably know, or at least can guess, hard drives are not monolithic entities with data simply spread haphazardly around the hard drive. Hard drives are organized into sectors and clusters. Data of any type is organized into files. Whether it is a document, image, spreadsheet, or even an executable program, it is a file. That file may be stored in one or more clusters.

Filesystems are responsible to organize, find, and work with those files that are on the hard drive. There are issues that any filesystem must address in order to handle files effectively.

The first issue occurs because many files are larger than a single sector or cluster. So, locating the entirety of a file on a hard drive is an issue that must be addressed. The operating system may need to check several clusters, not necessarily contiguous, to find a file.

Another problem is how to store the files in clusters and sectors. Also, a filesystem must address how to handle space left due to deleted or moved files.

Now since we know what is a File System, Let us start with the actual agenda of this article.

Commands to check file system type in Linux or Unix

1. blkid

blkid can determine the type of content (e.g. filesystem or swap) that a block device holds, and also the attributes (tokens, NAME=value pairs) from the content metadata (e.g. LABEL or UUID fields).

You can also create your own man page with a list of instructions for a script or a custom tool which you have created. In real time production environment it is always recommended to also create and release a man page for every script or tool we develop.

Читайте также:  Сколько весит linux lite

You must execute blkid as root user without any directives and check » TYPE » field to check file system type of respective partition or device in Linux or Unix.

[root@centos-8 ~]# blkid /dev/mapper/rhel-root: UUID="0b5322d5-887d-4c03-9933-b75c2a1ca880" TYPE="ext4" /dev/sda2: UUID="pXZ2Iy-hwtF-mFH2-nbej-0Yz9-Py2O-AqLQNH" TYPE="LVM2_member" PARTUUID="fcbab19d-02" /dev/sdb1: UUID="1b3910d9-11a9-4f68-894e-47a51bd077a8" TYPE="crypto_LUKS" PARTUUID="09181a39-01" /dev/sda1: UUID="2b857500-a7cf-4ec4-8453-0ef636943d86" TYPE="ext4" PARTUUID="fcbab19d-01" /dev/sr0: UUID="2019-08-15-21-52-52-00" LABEL="CentOS-8-BaseOS-x86_64" TYPE="iso9660" PTUUID="3e04f576" PTTYPE="dos" /dev/mapper/rhel-swap: UUID="cd18aa4a-e2d3-423c-b120-7fef1b1d9aac" TYPE="swap"

With -t, —match-token NAME=value , you can search for block devices with tokens named NAME that have the value value, and display any devices which are found. Common values for NAME include TYPE , LABEL , and UUID

For example to list and check file system type for ext4 FS:

[root@centos-8 ~]# blkid -t TYPE=ext4 /dev/mapper/rhel-root: UUID="0b5322d5-887d-4c03-9933-b75c2a1ca880" TYPE="ext4" /dev/sda1: UUID="2b857500-a7cf-4ec4-8453-0ef636943d86" TYPE="ext4" PARTUUID="fcbab19d-01"

2. lsblk

lsblk lists information about all available or the specified block devices. lsblk command provides more information, better control on output formatting, easy to use in scripts and it does not require root permissions to get actual information.

[root@centos-8 ~]# lsblk --fs NAME FSTYPE LABEL UUID MOUNTPOINT sda ├─sda1 ext4 2b857500-a7cf-4ec4-8453-0ef636943d86 /boot └─sda2 LVM2_member pXZ2Iy-hwtF-mFH2-nbej-0Yz9-Py2O-AqLQNH ├─rhel-root ext4 0b5322d5-887d-4c03-9933-b75c2a1ca880 / └─rhel-swap swap cd18aa4a-e2d3-423c-b120-7fef1b1d9aac [SWAP] sdb └─sdb1 crypto_LUKS 1b3910d9-11a9-4f68-894e-47a51bd077a8 sr0 iso9660 CentOS-8-BaseOS-x86_64 2019-08-15-21-52-52-00 sr1

3. df

df is another popular and most used command to display the amount of disk space available on the file system containing each file name argument. If no file name is given, the space available on all currently mounted file systems is shown.

Using -T directive with df command you can print file system type of all the mounted file systems.

[root@centos-8 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 2.4G 0 2.4G 0% /dev tmpfs tmpfs 2.4G 0 2.4G 0% /dev/shm tmpfs tmpfs 2.4G 8.6M 2.4G 1% /run tmpfs tmpfs 2.4G 0 2.4G 0% /sys/fs/cgroup /dev/mapper/rhel-root ext4 14G 9.2G 3.5G 73% / /dev/sda1 ext4 488M 129M 325M 29% /boot tmpfs tmpfs 479M 0 479M 0% /run/user/0

Alternatively you can specify a device with df command to check file system type of the respective device

# df -Th /boot /dev/sda1 ext4 488M 129M 325M 29% /boot

4. findmnt

findmnt will list all mounted filesystems or search for a filesystem. The findmnt command is able to search in /etc/fstab , /etc/mtab or /proc/self/mountinfo . If device or mountpoint is not given, all filesystems are shown.

Using —fstab directive, findmnt command will search in /etc/fstab and with -t it will limit the set of printed filesystems

[root@centos-8 ~]# findmnt --fstab -t ext4 TARGET SOURCE FSTYPE OPTIONS / /dev/mapper/rhel-root ext4 defaults /boot UUID=2b857500-a7cf-4ec4-8453-0ef636943d86 ext4 defaults

If used without any directive, findmnt command will give you long list of output with all bind mounts

[root@centos-8 ~]# findmnt -t ext4 TARGET SOURCE FSTYPE OPTIONS / /dev/mapper/rhel-root ext4 rw,rela ├─/boot /dev/sda1 ext4 rw,rela ├─/var/named/chroot/etc/localtime /dev/mapper/rhel-root[/usr/share/zoneinfo/Asia/Kolkata] │ ext4 rw,rela ├─/var/named/chroot/etc/named.root.key /dev/mapper/rhel-root[/etc/named.root.key] ext4 rw,rela ├─/var/named/chroot/etc/named.conf /dev/mapper/rhel-root[/etc/named.conf] ext4 rw,rela ├─/var/named/chroot/etc/named.rfc1912.zones /dev/mapper/rhel-root[/etc/named.rfc1912.zones] ext4 rw,rela ├─/var/named/chroot/etc/rndc.key /dev/mapper/rhel-root[/etc/rndc.key] ext4 rw,rela ├─/var/named/chroot/etc/crypto-policies/back-ends/bind.config │ /dev/mapper/rhel-root[/usr/share/crypto-policies/DEFAULT/bind.txt] │ ext4 rw,rela ├─/var/named/chroot/etc/protocols /dev/mapper/rhel-root[/etc/protocols] ext4 rw,rela ├─/var/named/chroot/etc/services /dev/mapper/rhel-root[/etc/services] ext4 rw,rela ├─/var/named/chroot/etc/named /dev/mapper/rhel-root[/etc/named] ext4 rw,rela ├─/var/named/chroot/usr/lib64/bind /dev/mapper/rhel-root[/usr/lib64/bind] ext4 rw,rela └─/var/named/chroot/var/named /dev/mapper/rhel-root[/var/named] ext4 rw,rela

5. file

file command is normally only attempts to read and determine the type of argument files. Specifying the -s option causes file to also read argument files which are block or character special files. This is useful for determining and to check file system types of the data in raw disk partitions, which are block special files

# file -s /dev/sda1 /dev/sda1: Linux rev 1.0 ext4 filesystem data, UUID=2b857500-a7cf-4ec4-8453-0ef636943d86 (needs journal recovery) (extents) (64bit) (large files) (huge files)

6. udevadm

udevadm command queries the udev database for device information stored in the udev database. It can also query the properties of a device from its sysfs representation to help creating udev rules that match this device.

Читайте также:  Linux узнать модель звуковой карты

Using —query you can query the database for the specified type of device data. The below command gives a long output so we will grep the required data to check file system type for our device /dev/sda1

# udevadm info --query=property /dev/sda1 | egrep "DEVNAME|ID_FS_TYPE" DEVNAME=/dev/sda1 ID_FS_TYPE=ext4

Some more commands and methods to determine filesystem type in Linux or Unix

Now above were some of the most used commands to check file system type but there are many other methods using which you can determine filesystem type

7. File /etc/fstab content

Normally all the devices we use are mounted via /etc/fstab file to make the mounting reboot persistent. So you can always refer /etc/fstab file to check file system type, for example:

# cat /etc/fstab /dev/mapper/rhel-root / ext4 defaults 1 1 UUID=2b857500-a7cf-4ec4-8453-0ef636943d86 /boot ext4 defaults 1 2 /dev/mapper/rhel-swap swap swap defaults 0 0

Here the first column of the file specifies the partition device path while the third column shows the file system type of the respective device.

8. File /etc/mtab content

Similar to /etc/fstab you can also refer /etc/mtab to get the list of currently mounted file system along with the file system type.

# grep root /etc/mtab /dev/mapper/rhel-root / ext4 rw,relatime 0 0

Here also the first column of the file specifies the partition device path while the third column shows the file system type of the respective device.

9. File /proc/mounts

Now /proc/mounts file refers /etc/mtab so this is not a new method but just another file which you can look into to check file system type in Linux or Unix.

10. mount command

Again, mount command will also refer /etc/mtab file to get the list of mounted file systems and can also help you determine file system type of individual devices.

# mount sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) devtmpfs on /dev type devtmpfs (rw,nosuid,size=2436780k,nr_inodes=609195,mode=755) securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)

Lastly I hope the methods and commands from the article to determine and check file system type on Linux and Unix was helpful. So, let me know your suggestions and feedback using the comment section.

Читайте также:  Системы linux для начинающих

Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

Источник

8 способов определить тип файловой системы в Linux (Ext2, Ext3 или Ext4, FAT32, NTFS)

Файловая система — это способ, которым файлы именуются, хранятся, извлекаются, а также обновляются на диске или разделе хранения; это способ организации файлов на диске.

Файловая система разделена на два сегмента, которые называются: данные пользователя и метаданные (имя файла, время его создания, время изменения, его размер и расположение в иерархии каталогов и т. д.).

В этом руководстве мы расскажем о семи способах определения типа файловой системы Linux, например Ext2, Ext3, Ext4, BtrFS, GlusterFS и многих других.

1. Использование команды df

Команда df сообщает об использовании дискового пространства файловой системой, чтобы включить тип файловой системы в конкретный раздел диска, используйте флаг -T, как показано ниже:

Полное руководство по использованию команды df можно найти в наших статьях:

2. Использование команды fsck

fsck используется для проверки и, при необходимости, для восстановления файловых систем Linux, она также может печатать тип файловой системы на указанных разделах диска.

Флаг -N отключает проверку файловой системы на наличие ошибок, он просто показывает, что будет сделано (но нам нужен только тип файловой системы):

fsck -N /dev/sda fsck -N /dev/sdb2

3. Использование команды lsblk

lsblk отображает блочные устройства, при использовании с параметром -f он также печатает тип файловой системы на разделах:

Вариант этой команды, выводящей краткие сведение об имени и файловой системе:

4. Использование команды mount

Команда mount используется для монтирования файловой системы в Linux, её также можно использовать для монтирования образа ISO, монтирования удалённой файловой системы Linux и многого другого.

При запуске без аргументов она выводит информацию о разделах диска, включая тип файловой системы, как показано ниже:

5. Использование команды blkid

Команда blkid используется для поиска или печати свойств блочного устройства, просто укажите раздел диска в качестве аргумента, например:

6. Использование команды file

Команда file определяет тип файла, флаг -s разрешает чтение блочных или символьных файлов, а -L разрешает переход по символическим ссылкам:

7. Использование findmnt

Программа findmnt показывает множество информации о блочных устройствах, точках монтирования, опциях монтирования и прочей сопутствующей информации. В том числе выводится информация о файловой системе устройств:

8. Использование файла fstab

Файл /etc/fstab — это файл статической информации о файловой системе (такой, как точка монтирования, тип файловой системы, параметры монтирования и т. д.):

Всё готово! В этом руководстве мы объяснили восемь способов определить тип файловой системы Linux. Вы знаете какой-либо метод, не упомянутый здесь? Поделитесь с нами в комментариях.

Связанные статьи:

Источник

Оцените статью
Adblock
detector