Trying to copy a directory with cp and it is taking forever (I think)

6,656

When you run into this kind of thing (which happens from time to time) there are a few things you could do.

First, you need a new prompt. If you are using a graphical user interface, this should be as easy as opening a new terminal window. If you are not, you should be able to switch to another tty by using Ctrl+Alt+F2 for example. Another alternative is to pause the current command using Ctrl+z. You can check what jobs you have paused using the command jobs and let the program run again by using, for example bg 1, where bg stands for background.

Once you have a prompt, and the program you think takes too much time is still executing, you can start doing some investigations. One thing to look at is whether the destination is actually being filled:

ls /home/danai/destination_folder

Run the command a few times. Does the output change? If so, you are fine. If not, we need to check further.

Check if your drive is filling up:

df

Run the command a few times - or put a watch on it:

watch df

Does the output change? Is there a drive (containing your home directory) filling up? If so, the command is running, and is working, and is copying something.

Have a look at what you are copying:

du --summarize -h /mnt/external/directory_to_be_copied

This will tell you, approximately, the size of the directory you are copying. This could give you a hint about how much time it will take.

If all this fails, the source might not really be a directory, but rather some kind of mean device filling up your file system. There are such devices. If you watch df you can see if a file system is filling up. If so, you probably want to abort.

Go back to the terminal or tty you used to start the cp (probably tty1 at Ctrl+Alt+F1, if you didn't already change it) or put the command back in the foreground using fg 1 (or whatever number your job had, but probably 1), and abort it with Ctrl+C.

As a side note - when you copy directories, you probably want to use cp -r to copy any subdirectories as well.

Share:
6,656

Related videos on Youtube

Danae Vogiatzi
Author by

Danae Vogiatzi

I am a Web Developer/ Computer Science student/ Nerd/ Huge Star Wars geek!!! I still don't fully understand the difference between a nerd and a geek. I don't like hardware stuff. I love coding. Coding is fun,creative and sometimes deadly. May the code be with you all.

Updated on September 18, 2022

Comments

  • Danae Vogiatzi
    Danae Vogiatzi over 1 year

    I connected an external hardrive in my pc. I switch to root. I have mounted the disk successfully! (Yay me!!)

    Now I want to copy an entire directory from the external hard drive to my local folder.

    So I did this:

    cp /mnt/external/directory_to_be_copied /home/danai/destination_folder
    

    It hasn't come up with an error. But as soon as I hit enter at the next line there is this _ underscore blinking. And it's been at least 5 minutes now.

    So is the cause that the directory I'm trying to copy is too large or is there something wrong??

    • Zanna
      Zanna over 7 years
      wait a bit longer...
    • Danae Vogiatzi
      Danae Vogiatzi over 7 years
      @Zanna I actually stopped the process with ctrl + c , switched to destonation directory and saw that some copying was made, so I guess I am gonna zip it first. Thanks a lot for taking the time though!!
    • David Foerster
      David Foerster over 7 years
      @DanaeVogiatzi: Compressing the data will not make the copy process faster but most likely slower. Just think of this: The amount of data to read and write stays the same but in addition you need to compress and decompress it.
    • muru
      muru over 7 years
      This is why rsync is preferable for large scale copying: rsync -a --info-progress2 source/ target
  • Kevin Bowen
    Kevin Bowen over 7 years
    NIce! Some clear and useful troubleshooting tips.