Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I need a shell (bash) script that can copy all files from one directory to another; where the source and target will be specified by the user calling the script.

Could someone help me with this?

share|improve this question

closed as too broad by Braiam, guntbert, saji89, Eric Carvalho, falconer Jan 6 at 12:35

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
You can do this in so many ways, post your script and any problem or questions you have. –  bodhi.zazen Jan 4 at 17:51
3  
AskUbuntu is not exactly the place to ask for someone to do your homework. –  Luís de Sousa Jan 4 at 18:03
    
A friendly suggestion - always google your problem first before posting it here. You will be surprised how many solutions you can find from googling. –  Faron Jan 4 at 19:12

3 Answers 3

Here's a little script...

#!/bin/bash
echo "..:: Script to copy source files/directories to another target location ::.."
echo "Supply the source file/directory below:"
read srcName
echo "Supply the target directory below:"
read dstName
echo " "
echo "..::  Copying from: Source -> Destination  ::.."
cp -rv -t "$dstName" "$srcName"
share|improve this answer
    
I'm a little noob on bash, but aren't you supposed to "declare" srcName and dstName before ? If not, why ? Thank you ! –  MrVaykadji Jan 5 at 15:46
1  
I'm no expert either.. never declared variables in bash.. this little intro. to bash programming mentions that you don't have to declare since they don't have a data-type so that you can directly use them in script when and where needed.. (a link to the official Bash Reference Manual)... –  rusty Jan 5 at 16:55
    
@MrVaykadji: ..but this one shows the control you can get over your variables using declare/typeset "Typing variables: declare or typeset" –  rusty Jan 10 at 5:07

I can't think why you'd need a script for this.

cp /path/to/sourcedir/* /path/to/target

If you don't want to over-write files that have the same name in the source and target directories, use the -n or --no-clobber option.

cp -n /path/to/sourcedir/* /path/to/target

If you want to include hidden files (i.e. those beginning with a dot), use

shopt -s dotglob

before executing the cp command.

share|improve this answer

i tried it and it work

find /path/to/A -name '*.deb' -exec cp -t /location/you/choose/ {} +

change the path and the location (change .deb to ur file extension)

share|improve this answer
    
what does this {} + represents ?? –  Tejendra Nov 17 at 11:02