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
No, you cant
smbclient [-U ADUser] -L localhost
Shows the shares, but you have to look this up in your smb.conf to find the path.
ADUser is a domain User that can at least list the samba shares.
-
1Do you have to specifiy an IP or name here, like
smbclient -L localhost
? At least for other machines one can saysmbclient -L 10.30.40.50 -U ourdomain\\myUsrName
Mar 13, 2018 at 6:32
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
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
-
-
Confirmed to miss usershares, I've improved on your script to include them– a1anJun 18, 2012 at 12:33
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.