20140331-5 选题,两篇关于 findmnt 的文章,或许二选一就可以

This commit is contained in:
DeadFire 2014-03-31 16:56:40 +08:00
parent cfea692e92
commit 87c0079d1d
2 changed files with 260 additions and 0 deletions

View File

@ -0,0 +1,149 @@
8 examples of findmnt command to check mounted file systems on Linux
================================================================================
### Mounted file systems and devices ###
The more common command to check mounted file systems on linux is the mount command which is used to not only list mounted devices, but also mount and unmount them as and when needed. Here is another nifty command called findmnt, that can be used to take a quick look at what is mounted where and with what options.
### Install findmnt ###
The findmnt command comes from the packages util-linux which is installed by default on most distros like Ubuntu, Fedora, Debian
$ aptitude search util-linux
i util-linux - Miscellaneous system utilities
$ yum info util-linux
### Using findmnt ###
#### 1. List the file systems ####
Running findmnt without any options would simply list out all the mounted file systems in a tree style layout.
$ findmnt
![](http://www.binarytides.com/blog/wp-content/uploads/2014/03/findmnt.png)
#### 2. Output in list format ####
The output can be formatted as a plain list, instead of the default tree style, using the l option making it convenient to read.
$ findmnt -l
TARGET SOURCE FSTYPE OPTIONS
/sys sysfs sysfs rw,nosu
/proc proc proc rw,nosu
/dev udev devtmpf rw,rela
/dev/pts devpts devpts rw,nosu
/run tmpfs tmpfs rw,nosu
/ /dev/disk/by-uuid/6fa5a72a-ba26-4588-a103-74bb6b33a763
ext4 rw,rela
/sys/fs/cgroup tmpfs rw,rela
/sys/fs/fuse/connections fusectl rw,rela
/sys/kernel/debug debugfs rw,rela
/sys/kernel/security securit rw,rela
/run/lock tmpfs rw,nosu
/run/shm tmpfs rw,nosu
/run/user tmpfs rw,nosu
/sys/fs/pstore pstore rw,rela
/media/13f35f59-f023-4d98-b06f-9dfaebefd6c1
/dev/sda8 ext4 rw,nosu
/media/4668484A68483B47 /dev/sda5 fuseblk rw,nosu
/proc/sys/fs/binfmt_misc binfmt_misc binfmt_ rw,nosu
/sys/fs/cgroup/systemd systemd cgroup rw,nosu
/run/user/1000/gvfs gvfsd-fuse fuse.gv rw,nosu
#### 3. df style output ####
Findmnt can produce a df style output reporting free and used disk space with the "-D" or "--df" option.
$ findmnt -D
SOURCE FSTYPE SIZE USED AVAIL USE% TARGET
devtmpfs devtmpfs 994.2M 0 994.2M 0% /dev
selinuxfs selinuxfs 0 0 0 - /sys/fs/selinux
tmpfs tmpfs 1001.5M 68K 1001.4M 0% /dev/shm
tmpfs tmpfs 1001.5M 724K 1000.8M 0% /run
tmpfs tmpfs 1001.5M 0 1001.5M 0% /sys/fs/cgroup
/dev/mapper/fedora-root ext4 6.5G 5.3G 811.6M 82% /
tmpfs tmpfs 1001.5M 60K 1001.5M 0% /tmp
/dev/sda1 ext4 476.2M 107.7M 339.6M 23% /boot
Note that the above option is not available till util-linux version 2.20, which happened to be the latest version on Ubuntu 13.10
#### 4. Read file systems from fstab ####
With the '-s' or '--fstab' option, findmnt shall read file systems only from the /etc/fstab file and /etc/fstab.d directory.
$ findmnt -s
TARGET SOURCE FSTYPE OPTIONS
/ /dev/mapper/fedora-root ext4 defaults
/boot UUID=18cde604-1c65-4ec8-8a8d-385df50ada3b ext4 defaults
swap /dev/mapper/fedora-swap swap defaults
#### 5. Filter filesystems by type ####
Findmnt can print out only specific file systems based on the type, for example ext4.
Multiple system types can be specified separated by a comma.
$ findmnt -t ext4
TARGET SOURCE FSTYPE OPTIONS
/ /dev/mapper/fedora-root ext4 rw,relatime,seclabel,data=ordered
└─/boot /dev/sda1 ext4 rw,relatime,seclabel,data=ordered
#### 6. Raw output ####
If you prefer a raw style ugly looking output then use the '-r' or '--raw' option.
$ findmnt --raw
TARGET SOURCE FSTYPE OPTIONS
/sys sysfs sysfs rw,nosuid,nodev,noexec,relatime
/proc proc proc rw,nosuid,nodev,noexec,relatime
/dev udev devtmpfs rw,relatime,size=4069060k,nr_inodes=1017265,mode=755
/dev/pts devpts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000
/run tmpfs tmpfs rw,nosuid,noexec,relatime,size=816716k,mode=755
/ /dev/disk/by-uuid/6fa5a72a-ba26-4588-a103-74bb6b33a763 ext4 rw,relatime,errors=remount-ro,data=ordered
/sys/fs/cgroup tmpfs rw,relatime,size=4k,mode=755
/sys/fs/fuse/connections fusectl rw,relatime
/sys/kernel/debug debugfs rw,relatime
/sys/kernel/security securityfs rw,relatime
/run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k
/run/shm tmpfs rw,nosuid,nodev,relatime
/run/user tmpfs rw,nosuid,nodev,noexec,relatime,size=102400k,mode=755
/sys/fs/pstore pstore rw,relatime
/media/13f35f59-f023-4d98-b06f-9dfaebefd6c1 /dev/sda8 ext4 rw,nosuid,nodev,relatime,errors=remount-ro,data=ordered
/media/4668484A68483B47 /dev/sda5 fuseblk rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other,blksize=4096
/proc/sys/fs/binfmt_misc binfmt_misc binfmt_misc rw,nosuid,nodev,noexec,relatime
/sys/fs/cgroup/systemd systemd cgroup rw,nosuid,nodev,noexec,relatime,name=systemd
/run/user/1000/gvfs gvfsd-fuse fuse.gvfsd-fuse rw,nosuid,nodev,relatime,user_id=1000,group_id=1000
That looks very neat
#### 7. Search by source device ####
To find the file system by the source device, specify the device path with or without the '-S' option
$ findmnt -S /dev/sda1
TARGET SOURCE FSTYPE OPTIONS
/boot /dev/sda1 ext4 rw,relatime,seclabel,data=ordered
#### 8. Search by mount point ####
To search file system by the mount directory , specify the directory with or without the '-T'/'--target' option.
$ findmnt -T /
TARGET SOURCE FSTYPE OPTIONS
/ /dev/mapper/fedora-root ext4 rw,relatime,seclabel,data=ordered
$ findmnt -T /media/4668484A68483B47
TARGET SOURCE FSTYPE OPTIONS
/media/4668484A68483B47 /dev/sda5 fuseblk rw,nosuid,nodev,relatime,user_id=0
### Summary ###
That was a little introduction to the findmnt command. There are few more options supported by findmnt which can be found in the man page.
--------------------------------------------------------------------------------
via: http://www.binarytides.com/linux-findmnt-command/
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出

View File

@ -0,0 +1,111 @@
Linux findmnt Command To Find Mounted Filesystems
================================================================================
The command findmnt is used to find mounted filesystems in Linux. This command will look for a particular filesystem in /etc/fstab, /etc/mtab or /proc/self/mountinfo.
### How To Install findmnt ###
The command findmnt comes in the package util-linux-ng, now renamed util-linux. The package comes with several other utilities such as hwclock. To install findmnt [download util-linux][1] from kernel.org ftp page.
### How To Install findmnt In Fedora ###
Fedora users can install the package as follows:
$ sudo yum install util-linux-ng
### Findmnt Default option ###
This command by default will give you a list of all filesystems mounted if no mountpoint or device is specified.
$ findmnt
![findmnt default](http://linoxide.com/wp-content/uploads/2014/03/findmnt-default.png)
### Findmnt Polling Mode ###
The command findmnt can be used to monitor changes in /proc/self/mountinfo file. The polling mode can be invoked by tying in your terminal the following command:
$ findmnt -p
alternatively
$ findmnt --poll
Any changes made to /proc/self/mountinfo file will automatically be updated on the terminal. At first you will not see any output but if try unplug and plugging your flash drive, the changes are reflected on the terminal as in the following example.
![findmnt poll](http://linoxide.com/wp-content/uploads/2014/03/findmnt-poll.png)
The time which polling mode will block can be restricted by **--timeout** or **--first-only** option.
### Timeout option ###
This option can be used along with --poll to limit the time polling mode will block to the time you explicitly set. **The timeout to be set is in milliseconds**. After the timeout period findmnt will no longer monitor for changes to the /proc/self/mountinfo file.
$ findmnt --poll --timeout 6000
![findmnt poll timeout](http://linoxide.com/wp-content/uploads/2014/03/findmnt-poll-timeout.png)
### First-only option ###
The first-only option will monitor for changes in the /proc/self/mountinfo file only for the first change and the command will no longer be in polling mode. The first change is displayed on the terminal and the prompt is returned to you. To use this option type on your terminal:
$ findmnt --poll --first-only
![findmnt poll first-only](http://linoxide.com/wp-content/uploads/2014/03/findmnt-poll-first-only.png)
### Imitating the command df output option ###
The command findmnt can also be used to imitate the output you would get if you used the df command. You can achieve this by running the command findmnt with the **--df** option as shown the following example.
$ findmnt --df
or
$ findmnt -D
This will give an almost identical output if you had run the command **df** with the **-h** option.
$ df -h
![findmnt imitate df](http://linoxide.com/wp-content/uploads/2014/03/findmnt-imitate-df.png)
### Findmnt list option ###
If you do not like the default tree output you can use the **--list** or **-l** option. This will print for you an output in a list format.
$ findmnt --list
Running this command will give you an output as follows:
![findmnt list](http://linoxide.com/wp-content/uploads/2014/03/findmnt-list.png)
### Findmnt Evaluate Option ###
The evaluate option will convert all tags for example LABEL, UUID, PARTUUID or PARTLABEL to the actual device name. This option can be combined with **--fstab** option to print all the filesystems in /etc/fstab. The **--fstab** option has its output in list format, and therefore there is no need to call the **--list** option when **--fstab** is used.
$ findmnt --fstab --evaluate
When the two options are combined as follows, the output will look like the example below:
![findmnt fstab evaluate](http://linoxide.com/wp-content/uploads/2014/03/findmnt-fstab-evaluate.png)
### Findmnt type option ###
This option allows you to limit the set of printed filesystems. Multiple filesystems can be specified and separated by a coma. In this example the command will search for ext4, ext3 and vfat filesystems.
$ findmnt -t ext4,ext3,vfat
![findmnt types](http://linoxide.com/wp-content/uploads/2014/03/findmnt-types.png)
### Conclusion ###
You can try out the different options for findmnt depending on your needs.
--------------------------------------------------------------------------------
via: http://linoxide.com/linux-command/powerful-findmnt-command/
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:ftp://ftp.kernel.org/pub/linux/utils/util-linux/