LinuxQuestions.org
Visit Jeremy's Blog.
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 11-28-2023, 06:03 PM   #16
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,710

Rep: Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899

A trailing slash after the source directory will copy the contents. No trailing slash copies the directory itself.
 
Old 11-28-2023, 06:16 PM   #17
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 michaelk View Post
A trailing slash after the source directory will copy the contents. No trailing slash copies the directory itself.
If the source contains directories and .txt, and I want all of them in to the external drive directory named 'new folder, should we slash or not slash in this case for the source?
Code:
rsync -avh "/media/asus/781E-438F" "/media/asus/One Touch/new folder"
"/media/asus/One Touch/new folder" has some older version of contents in "/media/asus/781E-438F"
 
Old 11-28-2023, 06:37 PM   #18
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,710

Rep: Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899
Without the trailing slash the directory will be copied into the "new folder" directory like:
"/media/asus/One Touch/new folder/781E-438F"

With the trailing slash the contents of 781E-438F will be copied to "/media/asus/One Touch/new folder/"

If you want everything be sure to use the -r flag.
 
Old 11-29-2023, 12:46 AM   #19
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
rsync has a huge amount of switches and options, I would suggest you two of them: -i and -n to see how does it work without actually doing anything.
https://superuser.com/questions/5766...ed-using-rsync
 
Old 11-29-2023, 10:12 PM   #20
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 michaelk View Post
Without the trailing slash the directory will be copied into the "new folder" directory like:
"/media/asus/One Touch/new folder/781E-438F"

With the trailing slash the contents of 781E-438F will be copied to "/media/asus/One Touch/new folder/"

If you want everything be sure to use the -r flag.
Thanks I used the 2nd option i.e with trailing slash at the end of 781E-438F. It was not a dry run and did the job. See below
Code:
rsync -avh "/media/asus/781E-438F/" "/media/asus/One Touch/new folder"
Haven't tried the first option you provided i.e. without trailing slash the directory. They look the same to me. I wouldn't mind doing a rsync dry-run on the first option so I can see the difference between the 2 options you provided i.e. without trailing slash the directory, would that look anything like this
Code:
rsync -avh dry-run "/media/asus/781E-438F" "/media/asus/One Touch/new folder"

Last edited by linux-man; 12-07-2023 at 09:04 PM.
 
Old 11-30-2023, 01:11 AM   #21
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,796

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
Yes. It would show all as updates, because all files would be created under a new 781E-438F directory.
 
Old 12-07-2023, 09:12 PM   #22
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
Yes. It would show all as updates, because all files would be created under a new 781E-438F directory.
Is this a yes for "this is the correct way to do a dry run" without trailing slash at end of usb stick named 781E-438F?
Code:
rsync -avh dry-run "/media/asus/781E-438F" "/media/asus/One Touch/new folder"
 
Old 12-08-2023, 12:20 AM   #23
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
no, all the short options started with a -, long options with --, so it is --dry-run.
But anyway, it is you who need it and you can check if it works for you as expected.
 
Old 12-08-2023, 12:32 AM   #24
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,796

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
The dry-run option needs two dashes:
Code:
rsync -avh --dry-run "/media/asus/781E-438F" "/media/asus/One Touch/new folder"
Then it will create and update
/media/asus/One Touch/new folder/781E-438F

Or perhaps you want to omit the "new folder":
Code:
rsync -avh --dry-run "/media/asus/781E-438F" "/media/asus/One Touch"
 
1 members found this post helpful.
Old 12-08-2023, 10:12 AM   #25
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Quote:
Originally Posted by linux-man View Post
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"
NO.
That command would create a directory "/media/asus/One Touch/new folder/781E=438F/ and place the content of the source in that folder. As used the source directory and its content would be copied to the destination.
Changing that to read
Code:
rsync -avh "/media/asus/781E-438F/" "/media/asus/One Touch/new folder"
would copy only the content of "781E-438F" to the directory "new folder".

You really need to read the man page for rsync, then make some trials to understand how that command interprets the source and what it does.
Source in the form "directory/" says to copy the content of "directory/" to the destination.
Source in the form "directory" says to copy the "directory" and all its content to the destination.
 
1 members found this post helpful.
Old 12-09-2023, 12:24 AM   #26
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 computersavvy View Post
NO.
That command would create a directory "/media/asus/One Touch/new folder/781E=438F/ and place the content of the source in that folder. As used the source directory and its content would be copied to the destination.
Changing that to read
Code:
rsync -avh "/media/asus/781E-438F/" "/media/asus/One Touch/new folder"
would copy only the content of "781E-438F" to the directory "new folder".

You really need to read the man page for rsync, then make some trials to understand how that command interprets the source and what it does.
Source in the form "directory/" says to copy the content of "directory/" to the destination.
Source in the form "directory" says to copy the "directory" and all its content to the destination.
A directory is a location for storing files on your computer?
A source directory is one that contains the source location for files on your computer?

If the source directory is the usb stick named "781E-438F" and
the contents are the folders within the usb stick "781E-438F" then
what benefit is there to rysnc the source if I know already the source of what I am copying over?

In my case the source directory is the files within a usb named "781E-438F", is that correct? If yes, then how is that any different from just rsync the contents of usb named "781E-438F"?

If I had instead went ahead and done rsync source directory plus the contents with the usb named "781E-438F" I would have ended up with what as a bonus (other than the contents)? The code for that would have looked like this below:
Code:
rsync -avh "/media/asus/781E-438F" "/media/asus/One Touch/new folder"
Would there have been any additional benefit conferred upon me if I had went with rynsc source directory plus the contents (as above) vs just rysnc the contents (which is what I went for)?

Last edited by linux-man; 12-09-2023 at 02:46 AM.
 
Old 12-09-2023, 05:13 AM   #27
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
Would there have been any additional benefit conferred upon me if I had went with rynsc source directory plus the contents (as above) vs just rysnc the contents (which is what I went for)?
I don't really understand, copying a directory means you will create another directory somewhere else (using the same name) and copy all the content from the source directory to the target directory.
Copying the content is almost the same, just you won't create a new [target] directory, but you specify an existing one.
 
Old 12-10-2023, 03:55 PM   #28
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
...copying a directory means you will create another directory somewhere else (using the same name) and copy all the content from the source directory to the target directory.
The name in this case is the name of the usb stick which in my case is "781E-438F". All content you copy over will end up looking like this e.g.
Code:
781E-438F/file-1
 781E-438F/file-2
I was trying to say, I don't see how copying the source directory name (781E-438F) along with everything else is important? I don't see why I need it.

Last edited by linux-man; 12-10-2023 at 04:00 PM.
 
Old 12-10-2023, 08:08 PM   #29
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Instead of debating this endlessly just try what was suggested to see for yourself which fits what you want to happen.

First try copying the data using
Code:
rsync -av "/media/asus/781E-438F" "/media/asus/new folder"
and look at the content of "/media/asus/new folder" to see what exactly happened. (It should contain a directory "/media/asus/new folder/781E-438F")
Then repeat using
Code:
rsync -av "/media/asus/781E-438F/" "/media/asus/new folder"
and again look at the content of "/media/asus/new folder". This time it should contain only the content of the source 781E-438F directory. (assuming you cleaned out the data copied in the first time)

No one is saying to copy the directory and content. We are explaining how rsync works and saying that if you only want the content to be copied then you must use the form that has the trailing / on the source directory name (my second example here)

Last edited by computersavvy; 12-10-2023 at 08:10 PM.
 
Old 12-11-2023, 01:24 AM   #30
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
The name in this case is the name of the usb stick which in my case is "781E-438F". All content you copy over will end up looking like this e.g.
Code:
781E-438F/file-1
 781E-438F/file-2
I was trying to say, I don't see how copying the source directory name (781E-438F) along with everything else is important? I don't see why I need it.
In the linux/unix world everything is [mapped to] a file or directory, the OS itself works only on files and directories. So the question is if you want to appear the name (781E-438F) on the target side (as a directory). It depends on you, if you need it or if you find it annoying.
 
1 members found this post helpful.
  


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 10:52 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