1

Is there a practical way, e.g. net command or other cli to get a list of all shares defined on a Linux server (Ubuntu distribution) listing not only the share name but also the full path to the local shared directory? Without having to look at samba config files or user shares files.

4 Answers 4

0

No, you cant

smbclient -L 

Shows the shares, but you have to look this up in your smb.conf to find the path.

1
  • 1
    Do you have to specifiy an IP or name here, like smbclient -L localhost ? At least for other machines one can say smbclient -L 10.30.40.50 -U ourdomain\\myUsrName
    – MacMartin
    Mar 13, 2018 at 6:32
2

Yes, you can.

The solution (found thanks to http://ubuntuforums.org/showthread.php?t=1304277&p=8186452#post8186452) is to look at the directory /var/lib/samba/usershares : it contains one file per share, and each file has a line starting with path= containing the local path

0
1

Try this script ... feel free to improve it

#!/bin/bash
while read line; do
    [[ "$line" =~ ^\[ ]] && name="$line"
    [[ "$line" =~ ^[[:space:]]*path ]] && echo -e "$name\t$line"
done </etc/samba/smb.conf
2
  • Nice one, I'll try it. Meanwhile I guess it will miss usershares
    – a1an
    May 31, 2012 at 12:12
  • Confirmed to miss usershares, I've improved on your script to include them
    – a1an
    Jun 18, 2012 at 12:33
0

At least two ways to do this:

1. mount

$ mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,nosuid,noexec,relatime,size=1959288k,nr_inodes=489822,mode=755)
...
# etc, etc

With no options, mount will list all mounted file systems. Two options are available:

  • -l : includes labels
  • -t <type> : filters the output by filesystem <type>; e.g. cifs`

See man mount for details. An example from my system:

$ mount -l -t cifs
//NetgearNAS-3/backup on /mnt/NetgearNAS/backup type cifs (rw,relatime,vers=1.0,cache=strict,username=seamus,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.1.246,soft,unix,posixpaths,serverino,mapposix,acl,rsize=1048576,wsize=65536,bsize=1048576,echo_interval=60,actimeo=1)
//SynologyNAS-1/backups on /mnt/SynologyNAS/backups type cifs (rw,relatime,vers=3.1.1,cache=strict,username=seamus,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.1.102,file_mode=0755,dir_mode=0755,soft,nounix,serverino,mapposix,rsize=4194304,wsize=4194304,bsize=1048576,echo_interval=60,actimeo=1,user=seamus)

2. findmnt

From man 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.

With no options, findmnt provides a neat listing of all mounted filesystems in tree format:

$ findmnt
TARGET                                SOURCE                 FSTYPE     OPTIONS
/                                     /dev/sda1              ext4       rw,relatime,errors=remount-ro
├─/sys                                sysfs                  sysfs      rw,nosuid,nodev,noexec,relatime
│ ├─/sys/kernel/security              securityfs             securityfs rw,nosuid,nodev,noexec,relatime
│ ├─/sys/fs/cgroup                    tmpfs                  tmpfs      ro,nosuid,nodev,noexec,mode=755

...

# etc, etc

findmnt has an extensive set of filtering and formatting options, making it well-suited for use in scripts where the output must be parsed - see man findmnt for details. In this case, if we wish to restrict the output to shares (as in the smb/cifs/nfs sense), the -t option is handy:

$ findmnt -t cifs,nfs4
TARGET                     SOURCE                           FSTYPE OPTIONS
/mnt/SynologyNAS/rpi_share SynologyNAS-1:/volume1/rpi_share nfs4   rw,relatime,vers=4.1,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,timeo=600,retrans=2,se
/mnt/NetgearNAS-3/backup   //NetgearNAS-3/backup            cifs   rw,relatime,vers=1.0,cache=strict,username=seamus,uid=0,noforceuid,gid=0,noforcegid,addr=192.16
/mnt/SynologyNAS/backups   //SynologyNAS-1/backups          cifs   rw,relatime,vers=3.1.1,cache=strict,username=seamus,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.