D
D
Dmitry Bannik2016-01-09 00:36:35
linux
Dmitry Bannik, 2016-01-09 00:36:35

How to determine the block device name from a folder?

How can I determine by the /home/test/ folder which block device it belongs to?
tried like this. but not in all cases it is suitable:
1e231e9a6a24471cb6bbb82d35fd0329.png2139f4b6eb034e2ca8388e388279620c.png
I would like to get the name of the block device and not uuid
Tell me a command that is not too long to determine ...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Bannik, 2016-01-09
@prodimon

jcmvbkbc Thanks for the tip on the stat
program here is the solution:

mount | grep " $(stat -c%m /home/dimon/win/) " | awk '{print $1}'

D
dpvpro, 2016-01-09
@dpvpro

#!/bin/bash

# в качестве параметра скрипта указываем папку

# берем результат работы в переменную
BLOCK=$(df $1 | awk '/dev/  {print $1}')

# если в строке содержится "by-uuid" то ...
if  ;
then
# обрабатываем одним способом
    blkid -U $(echo $BLOCK | cut -d/ -f5)

else
# если "by-uuid" нет, то просто выводим.
  	echo $BLOCK
fi

J
jcmvbkbc, 2016-01-09
@jcmvbkbc

find /dev -type b -print0 | xargs -0 stat -c '%02t%02T %n' | grep ^`stat -c %D <имя каталога>`

-- find finds all block devices, the first stat prints their major/minor number and name, grep selects only those whose major/minor matches the major/minor of the block device on which the directory resides.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question