Copying folder to NAS drive using terminal

Hello so I'm completely new to Ubuntu and I wanted to copy folders to my network drive. I understand how to copy files normally but I can't seem to copy over files to my network drive.

sudo cp /home/adam/file.txt smb://nas/main/

It says no such directory exists. I can navigate to the location through the file explorer.

EDIT2: Solution provided by RoVo works. I mounted the network drive permanently by editing the /etc/fstab file and adding the line to the end.

I can now transfer files with:

sudo cp /home/adam/file.txt /media/networkdrive

You cannot cd to a smb share like this.
Nautilus/Nemo can do that, because it uses a virtual file system (gvfs) in the background and mounts the share to a folder somewhere in your file system automatically.

After you fired Nautilus/Nemo to mount it, you could go to /run/user/1000/gvfs/[...] (compare your mount output) and voilà. You should see the smb share there.


From the terminal without Nautilus/Nemo you need to mount the smb drive manually. There are several options doing so.

Most common option afaik is using cifs. smbfs is an alternative. Alternatives for mounting smb in userspace (without the need of having sudo rights or being root) are described here or here or here.

Install cifs-utils:

sudo apt-get install cifs-utils

Then mount your drive

--> either temporarily:

sudo mount -t cifs -o <Options> //<Server>/<Sharename> <Mountpoint> 

Note: <MountPoint> must exist.

e.g.

sudo mount -t cifs -o credentials=~/.smbcredentials //nas/shared_folder /media/nas_shared

with ~/.smbcredentials being just a regular text file with following content:

username=<username of the share>
password=<password of the share>

Leave out the -o credentials=[...] part if it's a public share without login.

--> or permanent using fstab:

//<Server>/<Sharename> <Mountpoint> cifs credentials=/home/user/.smbcredentials  0 0

Then you can cd to <Mountpoint>.


Get more information from the Ubuntu WIKI.