Score:0

Trying to copy entire folder and subfolders from external HD to internal HD

in flag

I am a long time Windows user and just starting to use Ubuntu so forgive my newbie questions.

I am trying to copy all my data files from Windows to Ubuntu 20.04.2 LTS.

I have copied the data drive of the Windows to an external HD and am now trying to copy that to the internal Ubuntu Desktop HD. I got plenty of "permission denied" errors when trying to use the GUI similar to: Copying folder and subfiles/folders via terminal.

So I got the bright idea to use the terminal.

I first used lsblk to find the mountpoint of the external HD Then I tried (please don't laugh):

sudo cp -avr /MOUNTPOINToftheexternal/* ~/Desktop/SAVEDIRECTORY/

However it keeps saying:

cp: cannot stat '/MOUNTPOINToftheexternal/*': No such file or directory.

It says this despite my fiddling with the path the best I could think of.

This is what I want to do:

I would like to get from my external HD all the data files, preferably without personal metadata like owner, date created, where created, etc, to be copied to my internal Ubuntu HD.

I think that if I could change permissions I would not get the "permission denied" errors from the GUI method. However an attempt using the File Manager method failed.

Alternatively, I thought I could use the terminal using sudo but seem not to be able to find out the correct path I need to reach the external HD.

Someone told me about MAT (metadata anonymizing toolkit) which may be able to help eliminate the personal metadata but I heard that it may have a 2nd version and that it still doesn't take care of certain files like pdf or RAW files.

Please let me know what I am doing wrong and how I can go about doing something that seems like it would take me 5 min in Windows.
I have tried to search the internet and forums for this seemingly easy question without sufficient answers.

I tried asking this question, probably in a not very clear way before here: How do I copy my Windows 7 derived files off my USB to Ubuntu?

However, I must have not explained myself well because I tried the answer and it didn't work for me.

Thank you. I appreciate your time.

$ sudo df -h
Filesystem                 Size  Used Avail Use% Mounted on
udev                       7.8G     0  7.8G   0% /dev
tmpfs                      1.6G  1.7M  1.6G   1% /run
/dev/mapper/vgubuntu-root  456G  8.9G  424G   3% /
tmpfs                      7.8G     0  7.8G   0% /dev/shm
tmpfs                      5.0M  4.0K  5.0M   1% /run/lock
tmpfs                      7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/loop0                  65M   65M     0 100% /snap/gtk-common-themes/1514
/dev/loop4                  52M   52M     0 100% /snap/snap-store/518
/dev/loop2                  56M   56M     0 100% /snap/core18/2074
/dev/loop3                  56M   56M     0 100% /snap/core18/2128
/dev/loop7                  33M   33M     0 100% /snap/snapd/12883
/dev/loop6                  51M   51M     0 100% /snap/snap-store/547
/dev/loop5                 219M  219M     0 100% /snap/gnome-3-34-1804/72
/dev/loop8                  33M   33M     0 100% /snap/snapd/12704
/dev/loop1                 219M  219M     0 100% /snap/gnome-3-34-1804/66
/dev/loop9                  66M   66M     0 100% /snap/gtk-common-themes/1515
/dev/sda2                  705M  217M  437M  34% /boot
/dev/sda1                  511M  5.3M  506M   2% /boot/efi
tmpfs                      1.6G   32K  1.6G   1% /run/user/1000
/dev/sdb1                  1.9T  1.3T  548G  71% /media/user/External HD

The relevant permissions on the folder on the External HD that I want to copy are: drwxr-xr-x 4 user user 131072 Dec 31 2020 DATA save/

in flag
Let's get some specifics to better understand the issue. Could you [edit] your question to include: (1) the output of `sudo df -h` (2) the output of `sudo ls -AlF /MOUNTPOINToftheexternal` ⇠ replacing this last bit with the actual mount point of the external device. With this, it will be a little simpler to offer suggestions.
Score:2
cn flag

In order to copy files, you must have read permissions on the folders and files that you want to copy. On a typical Ubuntu system, you will have these permissions by default. That likely will not be your problem currently. So (by far) prefer to do the copy operation as normal user, not as administrator ("root").

The error message you provide:

cp: cannot stat '/MOUNTPOINToftheexternal/*': No such file or directory.

indicates that /MOUNTPOINToftheexternal/* does not exist. One way to obtain the correct pathname of the folder from which to copy from would be to

  1. Navigate to that folder in file manager
  2. Hit Ctrl+L. The location bar appears with the path written out. Just copy that to your clipboard (Ctrl+C).

Now, you can paste that path name in the command. Place it between quotes in case the path name contains spaces or other special characters. For example, suppose the path effectively is /MOUNTPOINToftheexternal:

cp -vr "/MOUNTPOINToftheexternal/"* ~/"Desktop/SAVEDIRECTORY/"

I removed the -a option, because you cannot keep this if you copy as a normal user. -a causes the copied files to inherit the same permissions and ownerships as the original. However, as normal user, you cannot set the owner to someone else, so the -a option would fail if files in the source belong to another user.

So do prepend the command with sudoif you want the permissions and ownerships to be identical as in the source, and/or source files are not accessible to you as user (they won't be in the copy either). So you may need to adjust ownerships of the copied files.

216ann avatar
in flag
Thanks so much for your patience. Maybe I am having a brain fart on something really easy. The path appears perfectly correct. And it took me a while to figure out that spaces require a "\" prior to it to register correctly in terminal. However, i have also been using a "~" in front of the path as well as a "/*" after the path to indicate that I want to copy all the files. Is that a problem? Also is the "-avr" giving me a problem? I heard that you may want to use "-a" and or "-r" to ensure that you copy all the subfolders, etc. Please advise. Thanks again.
216ann avatar
in flag
based on the sudo ls -AlF command that matigo suggests, the permissions of the file may need to be modified so that all the files copied don't end up being belonging to root. I tried using the file manager route but despite making the supposed changes, none of the permissions altered. Please advise. Appreciate it.
vanadium avatar
cn flag
Instead of \ before space, you can quote the entire path with "..." as in my answer. `-a` may indeed be the problem: that tries to set the permissions and ownerships the same as the original - however, as ordinary user, you cannot set the ownership to someone else. I will add that in the answer.
216ann avatar
in flag
So I could sudo cp -avr ~"/MOUNTPOINToftheexternal/"* "~/Desktop/SAVEDIRECTORY/" ??? It would also be cool to learn how I could just globally change the permissions on an entire directory/folder as well as the subfolders so that I could just copy using the GUI. I mean, I don't know if I want root to own everything but it would be nice to be able to transfer/move files without having to resort to the terminal each time. Thanks so much for the assistance.
vanadium avatar
cn flag
The format if this site is "one question - one answer". Feel free to open additional questions. A traditional forum is a more suited format for hands on guidance. Limit your copying as root to a strict minimum. For daily use, you do not need a terminal. For administrative tasks, how to use graphical tools correctly depends on the desktop environment.
216ann avatar
in flag
Sorry about that. I thought that posting new questions based on the same circumstances may be flagged as spam because I would have to re-explain all the same specifics again. I tried your "quote" method but it still claims no such file or directory while quoting the mount point exactly. Is the use of ~ before or * after the issue? After I eliminated the use of ~ before, I get the response that "~/Desktop/SAVEDIRECTORY/ " is not a directory. And target "/Desktop/SAVEDIRECTORY/" is also not a directory. But for sure, SAVEDIRECTORY is an empty folder on the Desktop that I can see and open
vanadium avatar
cn flag
Using the trick with the file manager gives you the full and correct path. Paste that on the terminal and surround by quotes. If you add `/*` to that path, you start referring to the filas and dirs inside: that path will be replaced by all full paths of the files in that dir. The last argument on the `cp` command is the target directory.
vanadium avatar
cn flag
Try `ls "/MOUNTPOINToftheexternal/"*`. Do you see the listing of the source files? Then you know the path is correct.
Martin Thornton avatar
cn flag
@216ann "I get the response that `"~/Desktop/SAVEDIRECTORY/"` is not a directory." That's because the answer should have been `~/"Desktop/SAVEDIRECTORY/"`. Also `~` doesn't mean what I think you think it means. See https://askubuntu.com/questions/85149/
vanadium avatar
cn flag
@MartinThornton thanks for this crucial correction!
216ann avatar
in flag
Thank you so much, I am finally copying files, now my next problem is that I can't seem to delete or access the saved files because I guess they belong to root or something. Should I ask on another post? Thanks again. I have finally made some progress.
vanadium avatar
cn flag
So then please "accept" this answer if it helped for this question: click the checkmark next to the question. You can indeed ask different questions, but also make sure to read yourself a little bit in on the basics of linux permissions before asking questions.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.