- How to list disks, partitions and filesystems in Linux? [duplicate]
- 3 Answers 3
- Example
- 4 Commands to List Mounted File Systems in Linux
- 1. View Linux Mounted Filesystem Using /proc Filesystem
- 2. List Linux Mounted Filesystem Using df Command
- 3. Print Linux Mounted Filesystems Using findmnt Command
- 4. Show Mounted Linux Filesystem Using mount Command
- Linux command to list file systems available for mounting?
- 3 Answers 3
- Ls Command in Linux (List Files and Directories)
- How to Use the ls Command #
- Long Listing Format #
- Show Hidden Files #
- Sorting the Output #
- List Subdirectories Recursively #
- Conclusion #
How to list disks, partitions and filesystems in Linux? [duplicate]
In Windows, if you type LIST DISK using DiskPart in a command prompt it lists all physical storage devices, plus their size, format, etc. What is the equivalent of this in Linux?
3 Answers 3
There are many tools for that, for example fdisk -l or parted -l , but probably the most handy is lsblk (aka list block devices):
Example
$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 238.5G 0 disk ├─sda1 8:1 0 200M 0 part /boot/efi ├─sda2 8:2 0 500M 0 part /boot └─sda3 8:3 0 237.8G 0 part ├─fedora-root 253:0 0 50G 0 lvm / ├─fedora-swap 253:1 0 2G 0 lvm [SWAP] └─fedora-home 253:2 0 185.9G 0 lvm
It has many additional options, for example to show filesystems, labels, etc. As always man lsblk is your friend.
@Dor it is worth explaining what additional options do, if you are recommending their use. -f or —fs shows the information about filesystems, such as format, crypto, raid member, etc. It is somewhat slower than the default though.
You’ll like this : you can do sudo lsblk —scsi and this shows the disk types including name(sda,sdb. ), scsi addr, type,vendor, model, rev, .. it’s easy to find which is which when you want to physically locate the disk.
Another way to quickly see the filesystems is the command df. On my machine (Finnish localization) it shows like this:
ptakala@athlon:/mnt$ df Tiedostojärjestelmä 1K-lohkot Käyt Vapaana Käy% Liitospiste /dev/root 38317204 19601752 16762352 54% / devtmpfs 4063816 0 4063816 0% /dev tmpfs 4097592 81988 4015604 3% /dev/shm tmpfs 4097592 10120 4087472 1% /run tmpfs 5120 8 5112 1% /run/lock tmpfs 4097592 0 4097592 0% /sys/fs/cgroup /dev/sda9 535267140 287403688 220666804 57% /work /dev/sda7 288239836 201635356 71956016 74% /home tmpfs 819520 4 819516 1% /run/user/113 tmpfs 819520 8 819512 1% /run/user/1000 /dev/sda1 39070048 37083304 1986744 95% /mnt/sda1 /dev/sda10 22662140 14032580 8629560 62% /mnt/sda10 /dev/sda5 29280176 20578032 8702144 71% /mnt/sda5
It won’t show the file system type, but usually that is non-essential, and you see by one eyedrop everything needed.
ptakala@athlon:/mnt$ df -h Tiedostojärjestelmä Koko Käyt Vapaa Käy% Liitospiste /dev/root 37G 19G 16G 54% / devtmpfs 3,9G 0 3,9G 0% /dev tmpfs 4,0G 89M 3,9G 3% /dev/shm tmpfs 4,0G 9,9M 3,9G 1% /run tmpfs 5,0M 8,0K 5,0M 1% /run/lock tmpfs 4,0G 0 4,0G 0% /sys/fs/cgroup /dev/sda9 511G 275G 211G 57% /work /dev/sda7 275G 193G 69G 74% /home tmpfs 801M 4,0K 801M 1% /run/user/113 tmpfs 801M 8,0K 801M 1% /run/user/1000 /dev/sda1 38G 36G 1,9G 95% /mnt/sda1 /dev/sda10 22G 14G 8,3G 62% /mnt/sda10 /dev/sda5 28G 20G 8,3G 71% /mnt/sda5
4 Commands to List Mounted File Systems in Linux
The Linux operating system provides multiple filesystems, including ext4, xfs, tmpfs, securityfs, and many more. This guide demonstrates various ways to list all mounted file systems in a Linux system.
1. View Linux Mounted Filesystem Using /proc Filesystem
The /proc/mounts file is a file that displays the status of all filesystems that are currently mounted on the system. The file format closely resembles that of the /etc/fstab file. The file reports the status of mounted filesystems as recorded by the Linux kernel.
Thus, to view all the mounted filesystems, view the /proc/mounts file using the cat command as shown.
2. List Linux Mounted Filesystem Using df Command
The df command is mostly used to check disk space utilization on mounted file systems. It lists, among other statistics, total disk space and available disk space on each mounted filesystem.
When the -a option is included, the df command lists all the mounted filesystems.
3. Print Linux Mounted Filesystems Using findmnt Command
The findmnt command is yet another powerful command that displays all mounted filesystems on your Linux system in a tree-like format.
To print all the mounted filesystems, simply run the command without any arguments.
This prints the output in a tree-like format as shown.
You can pass the -D option which will print the output similar to the df -Th command
Pass the -t option followed by the filesystem type to print specific filesystems. For example, to view all the mounted EXT4 filesystems, run the command:
To view all EXT4 filesystems mounted in the /etc/fstab file, run the command:
4. Show Mounted Linux Filesystem Using mount Command
You can also use the mount command to list all mounted file systems. Without any arguments, it lists all the mounted filesystems.
Summing Up
In this guide, we have explored four ways that you can use to list all mounted file systems in a Linux system. Your views and feedback on this guide are welcome.
Linux command to list file systems available for mounting?
What terminal command will return data that includes the file systems that are currently available for mounting on my system? Specifically, I am using Ubuntu 15.04, though I would prefer an answer that is valid for all *nix users. NOTES: I don’t want to know what IS mounted, I want to know what is available. I don’t want to check the type of file system (ext2, ext4, ntsf, etc.), I want to know which file systems are available to be mounted (sda2, fd1, etc.).
Do you mean which filesystems (e.g, ext4, xfs, tmpfs) are available, or what disk devices which potentially contain filesystems (e.g, sdb1, sdd3) are available?
@duskwuff No, I do not mean file system TYPES (ext4, etc.), I mean file systems (which are formatted to a type). Please see CompTIA for clarification of the terms.
What you are describing sounds like storage devices, not file systems. If CompTIA uses the phrase «file systems» to describe this, I’m sorry, but they are wrong.
3 Answers 3
On Ubuntu you can use to show discs:
or to check all partitions on your system
sudo blkid -o list | grep "not mounted"
or if you just want the device:
sudo blkid -o list | grep "not mounted" | awk ''
Just to point out, since you edited, the command sudo blkid -o list | grep «not mounted» is the one that was correct.
Regarding the question «command will return data that includes the file systems that are currently available for mounting on my system».
Granted from the powerful PROC file system, the available (or, static + dynamically installed) file systems in a running Linux could be found by:
In my linux 3.10.0, the result is:
$cat /proc/filesystems nodev sysfs nodev rootfs nodev ramfs nodev bdev nodev proc nodev cgroup nodev cpuset nodev tmpfs nodev devtmpfs nodev debugfs nodev securityfs nodev sockfs nodev dax nodev bpf nodev pipefs nodev configfs nodev devpts nodev hugetlbfs nodev autofs nodev pstore .
This is the meta-data, the «mount» command will find and use.
Then, with below command, it lists all the mounted file systems.
$cat /proc/mounts /dev/sda1 /boot xfs rw,relatime,attr2,inode64,noquota 0 0 . cgroup /sys/fs/cgroup/devices cgroup rw,nosuid,nodev,noexec,relatime,devices 0 0
The third field of each line, like xfs or cgroup, is the «file system», which is just mentioned in previous command.
Ls Command in Linux (List Files and Directories)
ls is one of the basic commands that any Linux user should know.
The ls command lists files and directories within the file system, and shows detailed information about them. It is a part of the GNU core utilities package which is installed on all Linux distributions.
This article will show you how to use the ls command through practical examples and detailed explanations of the most common ls options.
How to Use the ls Command #
The syntax for the ls command is as follows:
When used with no options and arguments, ls displays a list of the names of all files in the current working directory :
The files are listed in alphabetical order in as many columns as can fit across your terminal:
cache db empty games lib local lock log mail opt run spool tmp
To list files in a specific directory, pass the directory path as an argument to the ls command. For example, to list the contents of the /etc directory, you would type:
You can also pass multiple directories and files separated by space:
If the user you are logged in with doesn’t have read permissions to the directory, you will get a message saying that ls can’t open the directory:
ls: cannot open directory '/root': Permission denied
The ls command has a number of options. In the sections below, we will explore the most commonly used options.
Long Listing Format #
The default output of the ls command shows only the names of the files and directories, which is not very informative.
The -l ( lowercase L) option tells ls to print files in a long listing format.
When the long listing format is used, you can see the following file information:
- The file type.
- The file permissions.
- Number of hard links to the file.
- File owner.
- File group.
- File size.
- Date and Time.
- File name.
-rw-r--r-- 1 root root 337 Oct 4 11:31 /etc/hosts
Let’s explain the most important columns of the output.
The first character shows the file type. In this example, the first character is — , which indicates a regular file. Values for other file types are as follows:
- — — Regular file.
- b — Block special file.
- c — Character special file.
- d — Directory.
- l — Symbolic link.
- n — Network file.
- p — FIFO.
- s — Socket.
The next nine characters are showing the file permissions. The first three characters are for the user, the next three are for the group, and the last three are for others. You can change the file permissions with the chmod command. The permission character can take the following value:
- r — Permission to read the file.
- w — Permission to write to the file.
- x — Permission to execute the file.
- s — setgid bit.
- t — sticky bit.
In our example, rw-r—r— means that the user can read and write the file, and the group and others can only read the file. The number 1 after the permission characters is the number of hard links to this file.
The next two fields root root are showing the file owner and the group, followed by the size of the file ( 337 ), shown in bytes. Use the -h option if you want to print sizes in a human-readable format. You can change the file owner using the chown command.
Oct 4 11:31 is the last file modification date and time.
The last column is the name of the file.
Show Hidden Files #
By default, the ls command will not show hidden files. In Linux, a hidden file is any file that begins with a dot ( . ).
To display all files including the hidden files use the -a option:
drwxr-x--- 10 linuxize linuxize 4096 Feb 12 16:28 . drwxr-xr-x 18 linuxize linuxize 4096 Dec 26 09:21 .. -rw------- 1 linuxize linuxize 1630 Nov 18 2017 .bash_history drwxr-xr-x 2 linuxize linuxize 4096 Jul 20 2018 bin drwxr-xr-x 2 linuxize linuxize 4096 Jul 20 2018 Desktop drwxr-xr-x 4 linuxize linuxize 4096 Dec 12 2017 .npm drwx------ 2 linuxize linuxize 4096 Mar 4 2018 .ssh
Sorting the Output #
As we already mentioned, by default, the ls command is listing the files in alphabetical order.
The —sort option allows you to sort the output by extension, size, time and version:
- —sort=extension (or -X ) — sort alphabetically by extension.
- —sort=size (or -S ) — sort by file size.
- —sort=time ( or -t ) — sort by modification time.
- —sort=version (or -v ) — Natural sort of version numbers.
If you want to get the results in the reverse sort order, use the -r option.
For example, to sort the files in the /var directory by modification time in the reverse sort order you would use:
It’s worth mentioning that the ls command does not show the total space occupied by the directory contents. To get the size of a directory , use the du command.
List Subdirectories Recursively #
The -R option tells the ls command to display the contents of the subdirectories recursively:
Conclusion #
The ls command lists information about files and directories.
For more information about ls visit the GNU Coreutils page or type man ls in your terminal.
If you have any questions or feedback, feel free to leave a comment.