[SOLVED] How to copy file from one usb to another usb using rsyc in terminal?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: native install of Parrot Home Edition 5.0 Debian (no security tools) 64 bit, KDE, 5.14.0-9parrot1,
Posts: 872
Rep:
How to copy file from one usb to another usb using rsyc in terminal?
I need to rsync almost identical files from one usb to another. There are about say 20 yellow folders in both roughly. One has more files/folders than the other one . Do I need to rsync individually each yellow folder or is this done in one go? Is there a command that can rsync in one swoop all yellow folders and anything else?
The name of one usb is KINGSTON in capitals and the other is is something like ADC123. Using rysnc what commands do I type? Thanks in advance.
I think that will create /dir2/dir1
A trailing slash addresses the contents of the source dir:
Code:
sudo rsync -avH --delete /dir1/ /dir2
The -H will also reconstruct hardlinks.
--delete will delete any extraneous things on the destination dir.
/dir1 is where the source disk is mounted,
/dir2 is where the destination disk is mounted.
Distribution: native install of Parrot Home Edition 5.0 Debian (no security tools) 64 bit, KDE, 5.14.0-9parrot1,
Posts: 872
Original Poster
Rep:
Quote:
Originally Posted by MadeInGermany
Code:
sudo rsync -avH --delete /dir1/ /dir2
The -H will also reconstruct hardlinks.
--delete will delete any extraneous things on the destination dir.
Are you certain nothing will get deleted in the each of the usb's? I don't want to delete anything in the destination file (usb-2) that is not in the other file(usb-1)
I know what softlinks are but not sure about hardlinks, how do I know I have hardlinks in either usb?
I don't want to be deleting or losing files in the destination usb, both usb's are similar but one is more current version, I am backing up files to the destination usb.
If the usb-1 is called ABC123 and the desitnation is called KINGSTON (usb-2) how would the code look like instead of below
Code:
sudo rsync -avH --delete /dir1/ /dir2
Will the above work regardless of which linux distro you are on?
If you just want to add/overwrite files to/on the destination then omit the --delete.
/dir1 and/dir2 is an example where the usbs got mounted.
Perhaps there is an automount happening? Check with the command
df -lh
Otherwise you must manually mount each usb device (named /dev/...) to an existing empty directory (for example /mnt/dir1 and /mnt/dir2). The rsync works with the directories (where the files are visible).
Distribution: native install of Parrot Home Edition 5.0 Debian (no security tools) 64 bit, KDE, 5.14.0-9parrot1,
Posts: 872
Original Poster
Rep:
Quote:
Originally Posted by MadeInGermany
If you just want to add/overwrite files to/on the destination then omit the --delete.
Say I have 20 yellow folders in usb stick called ABC123,plus files X,Y,Z which aren't in yellow folders and say
I have a usb called KINGSTON with the indentical 20 yellow folders plus files which aren't in yellow folders called Q,W,K.
How do I back up all files on usb stick with the name of ABC123 to usb with name of KINGSTON given the above situation without losing any files. Would the command for that be (below)
Code:
sudo rsync -avH "/ABC123/KINGSTON"
Quote:
Originally Posted by MadeInGermany
/dir1 and/dir2 is an example where the usbs got mounted.
Perhaps there is an automount happening? Check with the command
df -lh
I usually click Mount in bottom lower right hand corner where the icon tray is. Why what's wrong if it automount? It had always asked me to click mount first so that rules automount out.
Quote:
Originally Posted by MadeInGermany
Otherwise you must manually mount each usb device (named /dev/...) to an existing empty directory (for example /mnt/dir1 and /mnt/dir2). The rsync works with the directories (where the files are visible).
I manually mount by clicking bottom right hand lower side of screen near the clock.To do that in terminal what commands would I use?
Distribution: native install of Parrot Home Edition 5.0 Debian (no security tools) 64 bit, KDE, 5.14.0-9parrot1,
Posts: 872
Original Poster
Rep:
Quote:
Originally Posted by pan64
Rsync works the same way on all OSs, but different filesystems may behave differently (for example rsyncing to ntfs may cause surprises).
When usb sticks are shipped out to stores what are they as default FAT or NTFS? I thought you just open up the usb package and stick it in and your ready to go regardless?
When usb sticks are shipped out to stores what are they as default FAT or NTFS? I thought you just open up the usb package and stick it in and your ready to go regardless?
Some rsync options use filesystem features that are not implemented on fat and/or ntfs.
Here it is open if "my folder" is a directory or a file: if rsync finds that "my folder" is a directory then it would copy the "abc.txt" into it, otherwise it would copy the "abc.txt" to the filename "my folder".
Last edited by MadeInGermany; 09-29-2023 at 01:43 AM.
I would suggest a slightly different approach with rsync.
YES, you need to understand the naming and how rsync works before you start.
mount the first (source) usb at a given location such as /mnt/dir1
mount the second (destination) usb at another given location such as /mnt/dir2
If there are a relatively few files in the root of dir1 that you want to exclude and you do not want to delete anything on dir2 then the simplest rsync command I can suggest would be to have a list of the files in dir1 that you do not wish copied then do
where the file names file1,file2,... etc are the actual file names to exclude from copying.
You also could place the file names to be excluded into a file then modify the exclude option to use "--exclude-from=FILE" to get the list from the file instead of the command line.
Note that rsync always assumes the names of the excluded files are using the source directory as the origin for the path.
I always suggest that one do a trial run with any such command to a temporary destination location to confirm it does as expected before committing to the actual destination. The trial run allows one to verify the command does as expected and does no harm. You also can add the dry run option "--dry-run" or "-n" to the command to see the results live but without actually modifying any data.
Study the man page for rsync to understand it completely.
Distribution: native install of Parrot Home Edition 5.0 Debian (no security tools) 64 bit, KDE, 5.14.0-9parrot1,
Posts: 872
Original Poster
Rep:
This is a slightly different question to the one I asked a while back.
If I want to rsync everything on a usb called /media/asus/781E-438F to a directory called 'new folder' on an external drive named One Touch. Would the terminal command look like this?Thanks in advance.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.