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

This is what I am trying to achieve.

  • I have two folders SRC and DESTINATION. SRC contains several subdirectories and files in it.
  • A batch file should be built upon clicking it the following should be done
    1. Delete all contents from DESTINATION folder
    2. Copies all the files/subdirectories from SRC to DESTINATION

Can someone help me with this ?.

If this activity requires significant effort (I don’t know whether the above is simple to implement or not), do point me some resources for me to dig into it.

share|improve this question
This is not Ubuntu specific. Additionally: how sohuld the (bash-) script know the SRC and DEST parameters without providing them manually? The two functions you are looking for are rm -rf and cp -r. Read their man pages, if you are unsure about what they do. – onse Sep 9 '13 at 14:56
rsync may be something to look into – Mateo Sep 11 '13 at 0:44
up vote 2 down vote accepted

Create the following file using your favorite (plain) text editor (e.g. gedit or kwrite)



rm -rf "$dest_dir/*" #Remove the contents of DESTINATION
cp -r "$source_dir/* $dest_dir/" #Copy the contents of SRC into DESTINATION

The above should be saved with a meaningful name; e.g. and made executable with

chmod +x /path/to/

from a terminal

Now, in your file manager, navigate to where you saved the file, double-click on it and choose "Run".


  • As onse commented, you should edit the script file and manually enter the actual names of your directories instead of SRC and DESTINATION in the above listing.
  • Replace /path/to/ in the chmod line above with the actual path where you saved the script file.
share|improve this answer

Why don't just use cp and rm?

cp -R will copy all files and folders from selected location to other and rm -R will remove all files and folders from selected location.

cp -R <sourde> <destination>
rm -R <directory to remove>

Tou may also use rmdir for removing directories.

I think this two simple steps don't need to write a executable file for it.

share|improve this answer

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.