To list files from an SMB share on a macOS system via the command line, you can use the ls command after mounting the SMB share. Here’s a step-by-step guide:
1. Mount the SMB Share
First, you need to mount the SMB share to your macOS. You can do this using the mount_smbfs command or the more modern mount -t smbfs command. However, the easiest way is to use the connect to server functionality in Finder or the open command in Terminal.
Using open command:
open smb://username:password@server_address/share_name
Replace username, password, server_address, and share_name with your actual credentials and server details.
Alternatively, mount via command line:
mount_smbfs //username:password@server_address/share_name /Volumes/SMBShare
This will mount the SMB share to the /Volumes/SMBShare directory.
2. List Files in the Mounted SMB Share
Once the SMB share is mounted, you can use the ls command to list the files in the mounted directory.
ls /Volumes/SMBShare
This will display the contents of the SMB share.
3. Unmount the SMB Share (Optional)
After you’re done, you can unmount the SMB share using the umount command:
umount /Volumes/SMBShare
Example Workflow
Here’s a complete example:
# Mount the SMB share
mount_smbfs //user:password@192.168.1.100/myshare /Volumes/SMBShare
# List files in the mounted SMB share
ls /Volumes/SMBShare
# Unmount the SMB share
umount /Volumes/SMBShare
Alternative: Using smbutil or smbc
If you prefer not to mount the share, you can use smbutil or smbc to list files directly over SMB, though these tools are less common and may require additional setup.
Using smbutil:
smbutil view //username:password@server_address/share_name
Using smbc (if installed):
smbc -U username //server_address/share_name
Notes:
- Ensure that the SMB server is accessible from your macOS machine and that the credentials are correct.
- If you’re using a modern SMB version (e.g., SMB3), ensure that your macOS system supports it.
- If you encounter permission issues, you may need to adjust the ownership or permissions of the mounted volume.
This should allow you to list files from an SMB share directly from the macOS command line.