20

I have a folder I just luckily recovered sitting on:

/media/sdc1/Pictures

with a BUNCH of subdirectories and files that I need.

I want to copy these to a folder on:

/media/sdb1/Pictures

What command do I have to use in the terminal to make sure this happens? I know there is the cp command. But is that the best choice? And if so what options should I use to ensure I get every single directory and file?

24

I would use rsync for this so that if there is an error (or you need to stop copying) partway through you can easily resume later, without having to recopy everything.

rsync -av /media/sdc1/Pictures/ /media/sdb1/Pictures/
4
  • 3
    I'd remove the * since it will omit dotfiles at the first level. It may also cause it to exceed the ARG_MAX limit.
    – geirha
    Jun 1 '13 at 9:31
  • @geirha good point. edited.
    – amc
    Jun 1 '13 at 18:09
  • And to resume I need to use the same command again?
    – Pithikos
    Apr 14 '20 at 20:23
  • Yes, rerunning the command will reassess what’s changed and resume the transfer, effectively picking up where it left off previously
    – amc
    Apr 14 '20 at 20:25
12

cp -r /media/sdc1/Pictures/* /media/sdb1/Pictures/some_dir

  • The -r is recursive, read the man page...
  • With /media/sdc1/Pictures/* the asterisk is to copy all the contents of /media/sdc1/Pictures/, but not the parent directory itself.
  • The some_dir of /media/sdb1/Pictures/some_dir is where you want to put it.
1
  • will this copy dotfiles and dotdirs as well?
    – farinspace
    Apr 28 '18 at 5:52
1

If you need an exact image, use the command dd if=(path) of=(path)

2
  • 4
    Beware, this command could completely kill you computer if used incorrectly
    – MikeSchem
    Apr 10 '17 at 21:03
  • You can't copy directories with dd!
    – mook765
    Aug 7 '18 at 8:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.