21

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?

3 Answers 3

27

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, 2013 at 9:31
  • @geirha good point. edited.
    – amc
    Jun 1, 2013 at 18:09
  • And to resume I need to use the same command again?
    – Pithikos
    Apr 14, 2020 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, 2020 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, 2018 at 5:52
0

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

3
  • 4
    Beware, this command could completely kill you computer if used incorrectly
    – MikeSchem
    Apr 10, 2017 at 21:03
  • 1
    You can't copy directories with dd!
    – mook765
    Aug 7, 2018 at 8:11
  • WARNING: I don't have enough rep to downvote but this command is not suitable for copying directories, and in the worst case can trash your system.
    – PatS
    Feb 7, 2023 at 21:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .