LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 08-19-2023, 02:51 AM   #1
linux-man
Member
 
Registered: Nov 2016
Location: Geneva
Distribution: native install of Parrot Home Edition 5.0 Debian (no security tools) 64 bit, KDE, 5.14.0-9parrot1,
Posts: 872

Rep: Reputation: Disabled
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.
 
Old 08-19-2023, 03:45 AM   #2
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,496

Rep: Reputation: Disabled
I believe the command would be
Code:
sudo rsync -av --delete /dir1 /dir2
but wait for confirmation from someone who uses it regularly.

This is from my notebook.
(copies/updates/removes old)
 
Old 08-19-2023, 05:36 AM   #3
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,796

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
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.
 
1 members found this post helpful.
Old 08-20-2023, 12:07 AM   #4
linux-man
Member
 
Registered: Nov 2016
Location: Geneva
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: Reputation: Disabled
Quote:
Originally Posted by MadeInGermany View Post
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?

Last edited by linux-man; 08-20-2023 at 01:25 AM.
 
Old 08-20-2023, 01:48 AM   #5
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,796

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
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).
 
Old 08-20-2023, 08:56 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,855

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
Quote:
Originally Posted by linux-man View Post
Will the above work regardless of which linux distro you are on?
Rsync works the same way on all OSs, but different filesystems may behave differently (for example rsyncing to ntfs may cause surprises).
 
Old 08-20-2023, 08:09 PM   #7
linux-man
Member
 
Registered: Nov 2016
Location: Geneva
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: Reputation: Disabled
Quote:
Originally Posted by MadeInGermany View Post
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 View Post
/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 View Post
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?

Last edited by linux-man; 08-20-2023 at 08:14 PM.
 
Old 08-20-2023, 08:11 PM   #8
linux-man
Member
 
Registered: Nov 2016
Location: Geneva
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: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
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?
 
Old 08-20-2023, 11:19 PM   #9
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
What is a "yellow folder". I can guess that "folder" you mean directory, but in what way is it "yellow"?
 
Old 08-20-2023, 11:39 PM   #10
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Quote:
Originally Posted by linux-man View Post
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.

Evo2.
 
1 members found this post helpful.
Old 08-22-2023, 09:56 PM   #11
linux-man
Member
 
Registered: Nov 2016
Location: Geneva
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: Reputation: Disabled
Quote:
Originally Posted by evo2 View Post
What is a "yellow folder". I can guess that "folder" you mean directory, but in what way is it "yellow"?
Dolphin File Manager populates the screen with yellow folders (directories) when your looking at the contents of a usb stick on your screen.
 
Old 09-28-2023, 09:59 PM   #12
linux-man
Member
 
Registered: Nov 2016
Location: Geneva
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: Reputation: Disabled
rysnc usb file to external drive

I have a file called abc.txt file on a usb named
Code:
/media/asus/781E-438F/my folder/abc.txt
that I write notes often in and need to back up very often during the day to an external drive named "One Touch" where it already resides as well.

If I have abc.txt open already in Kate editor,would the rysnc command look something like this:
Code:
rsync -avh "/media/asus/781E-438F/my folder/abc.txt" "/media/asus/One Touch/my folder/abc.txt"
 
Old 09-29-2023, 01:35 AM   #13
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,796

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
Yes.

If the filename on the destination is the same then you can omit it:
Code:
rsync -avh "/media/asus/781E-438F/my folder/abc.txt" "/media/asus/One Touch/my folder/"
The trailing / says that "my folder" must be an existing directory, otherwise rsync would create it.
Compare with
Code:
rsync -avh "/media/asus/781E-438F/my folder/abc.txt" "/media/asus/One Touch/my folder"
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.
 
1 members found this post helpful.
Old 09-30-2023, 11:36 AM   #14
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
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
Code:
rsync -av --exclude=file1,file2,...fileN /mnt/dir1/ /mnt/dir2/
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.
 
1 members found this post helpful.
Old 11-28-2023, 05:51 PM   #15
linux-man
Member
 
Registered: Nov 2016
Location: Geneva
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: Reputation: Disabled
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.
Code:
rsync -avh "/media/asus/781E-438F" "/media/asus/One Touch/new folder"

Last edited by linux-man; 11-28-2023 at 06:08 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to copy all files from one usb to another external device within dolphin file manager, no terminal. linux-man Linux - Newbie 2 07-23-2022 03:43 AM
copy installation from one HDD to another, which directory NOT to copy? bfzhou Linux - Newbie 9 03-16-2016 11:59 AM
Want to change how pasted files are named "(copy)," "(another copy)," "(3rd copy)" L a r r y Linux - Desktop 3 08-24-2013 03:39 PM
How to copy one line from one file to another file on line number.. gajananh999 Linux - Newbie 1 08-13-2012 05:27 AM
[SOLVED] Can't copy-paste from one terminal to another using vim cola Slackware 11 12-18-2009 10:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration