3

If i have 8 directories under / , with 5 directories on different mountpoints then /

/dev/md/dsk/d0          49G    32G    17G    66%    /
/dev/md/dsk/d65         76G    77M    75G     1%    /u03
/dev/md/dsk/d64        345G    76G   266G    23%    /u02
/dev/md/dsk/d5          76G    77M    75G     1%    /u01
/dev/dsk/emcpower0g    591G   288G   297G    50%    /db
/dev/dsk/emcpower1g    591G   116G   469G    20%    /db2

Doing a ls -l

bash-3.2# pwd
/
bash-3.2# ls -l

drwxr-xr-x   3 root     sys          512 Jun 24  2014 boot
**drwxr-xr-x   5 root     root         512 Sep 16  2014 db
drwxr-xr-x   6 root     root         512 Sep 16  2014 db2
drwxr-xr-x  19 root     sys         5120 Jul 11 22:57 dev
drwxr-xr-x   2 root     sys          512 Jul 11 16:17 devices
drwxr-xr-x   3 root     root         512 Jun 25  2014 u01
drwxr-xr-x   4 root     root         512 Jul 11 17:08 u02
drwxr-xr-x   3 root     root         512 Sep  3  2014 u03

How do i filter/list to show

a) only those files and the other 3 directories (/boot, /dev, /devices..) that is created under / mountpoint

b) the 5 directories (e.g. /db, /db2, /u01..) that is under / but is mounted on different mointpoints

Noob
  • 303

2 Answers2

1

For question b (directories on mount different from root):

{
  stat --printf='%d\n' /
  find / -mount -maxdepth 1 -type d -printf '%D%p\n'
} | awk -F/ 'NR==1{root=$1}; $2!=""&&$1!=root{print "/"$2}'

stat spits out the decimal device number of the root device. Then the find command lists the directories directly under /, together with the decimal device number. The output of both these commands is sent to awk. The awk prints out the directories if the device number does not equal the root device. The $2!=""&& is there to filter out the actual root directory when answering the first question.

Change the last != to == in the awk program to find directories part of the first question.

joepd
  • 2,397
1

On a linux system you can use findmnt:

set ''
for r in /*
do  findmnt "$r"   || 
  ! set '' "$r$@"  &&
    ls "$r"
done

That command will do the ls for the other mounts, and all of the / root-mount filenames are available in $@ when you're ready. So to list those you'd do:

ls "$@"
mikeserv
  • 58,310