Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have to copy the file from my desktop to my mounted directory. I was using the following command to copy the file from my desktop to mounted directory.

 os.system("cp -f /home/Desktop/filename /media/folder_1"). 

It works fine. But the problem is while copying the file from my source to mounted directory(folder_1) if any interruption is happens like network down, then the system continuously keep on trying. It couldn't skip that process. Finally, when the network comes the files are again copy to my mounted directory. Due to this continuous trying, next time i try to move the content it throws "permission denied" error.

How do i copy the file only once, if any network issues happen then it will not keep try to copy, instead of that, it throws the error. If you know, Let me. Its very useful to me.

share|improve this question

Many people are using the os.system call way too much. You're running a Python script, then run Python, not Bash!

Using os.system will greatly reduce the functionality of your program. You are experiencing one great downside, you'll have to ask os.system if something went wrong with the call. Just use Python methods and capture the exception.

In Python, copying data is done through the shutil module.

share|improve this answer

the -f argument is your problem.

from the man page

-f, --force

    if an existing destination file cannot be opened, remove it  and
    try again 

you may want --remove-destination

share|improve this answer
also os.system is python so assuming your tring to do something in python. MUCH BETTER to use language level stuff for that. Here is a link – coteyr Nov 16 '12 at 5:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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