Try:

cp main/*/* /path/to/otherfolder/

If you want to be warned before overwriting a file, use the -i option:

cp -i main/*/* /path/to/otherfolder/
Answer from John1024 on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ bash โ€บ bash_cp.php
Bash cp - Copy Files and Directories
Bash Syntax Bash Script Bash Variables ... ... It's like making a duplicate of your file or folder. To copy a file, use cp source_file destination_file:...
๐ŸŒ
nixCraft
cyberciti.biz โ€บ nixcraft โ€บ howto โ€บ bash shell โ€บ linux copy file command [ cp command examples ]
Linux Copy File Command [ cp Command Examples ] - nixCraft
April 6, 2023 - The syntax is as follows to copy files and directories using the cp command: $ cp SOURCE DEST $ cp SOURCE DIRECTORY $ cp SOURCE1 SOURCE2 SOURCE3 SOURCEn DIRECTORY $ cp [OPTION] SOURCE DEST $ cp [OPTION] SOURCE DIRECTORY Where,
๐ŸŒ
Linux Hint
linuxhint.com โ€บ copy-files-list-bash-script
Copy List of Files Using Bash Script โ€“ Linux Hint
In this article, we learn about how to copy files using bash scripting. We can use many other operations like a loop, if-else, etc. Bash scripting is more effective when working with multiple commands to perform specific tasks.
๐ŸŒ
Earth Data Science
earthdatascience.org โ€บ home
Bash Commands to Manage Directories and Files | Earth Data Science - Earth Lab
July 15, 2019 - Thus, the newly created homeworks ... copy a specific file to a new directory using the command cp followed by the name of the file you want to copy and the name of the directory to where you want to copy the file (e.g....
๐ŸŒ
SS64
ss64.com โ€บ bash โ€บ cp.html
cp Man Page - Linux
-d, --no-dereference preserve links -f, --force remove existing destinations, never prompt -i, --interactive prompt before overwrite -l, --link link files instead of copying -p, --preserve preserve file attributes if possible -P, --parents append source path to DIRECTORY -r copy recursively, non-directories as files --sparse=WHEN control creation of sparse files -R, --recursive copy directories recursively -s, --symbolic-link make symbolic links instead of copying -S, --suffix=SUFFIX override the usual backup suffix -u, --update copy only when the SOURCE file is newer than the destination file
๐ŸŒ
nixCraft
cyberciti.biz โ€บ nixcraft โ€บ howto โ€บ linux โ€บ how to copy one file contents to another file in linux
How to copy one file contents to another file in Linux - nixCraft
March 28, 2022 - You need to use the cp command. It is used to copy files and directories. The copies become independent of the originals. Any subsequent change in one will not affect the other. This page shows how to use cp command to copy one file contents ...
Find elsewhere
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ the-linux-cp-command-how-to-copy-files-in-linux
The Linux cp Command โ€“ How to Copy Files in Linux
June 6, 2022 - If you spend more time in the user interface of your device, you'll probably use your mouse to do this. You can copy files by right-clicking on the file and selecting "Copy", then going to a different directory and selecting "Paste".
๐ŸŒ
PhoenixNAP
phoenixnap.com โ€บ home โ€บ kb โ€บ sysadmin โ€บ how to copy files and directories in linux
How to Copy Files and Directories in Linux (With Examples)
December 19, 2025 - Note: The cp command in Linux does not provide a warning before overwriting existing files. Use the โ€“i option for the system to prompt you before overwiting a file. Enter the following command to copy a file from the current working directory ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ linux-unix โ€บ cp-command-linux-examples
cp Command in Linux - GeeksforGeeks
4 days ago - The -i option enables interactive mode for the cp command. In this mode, cp asks for user confirmation before overwriting an existing destination file. By default, cp overwrites files silently.
Top answer
1 of 7
184

You can use cp with the -r (copy recursively) flag and specify the new directory name:

cp -r /path/to/directory /path/to/location/new-name

In the above command replace the given paths with the real ones.

For example, to copy stuff from my home directory to an existing directory named backup and name the new directory stuff-backup (if this directory already exists, note that stuff will be copied into it, not overwrite it), you run:

cp -r ~/stuff ~/backup/stuff-backup

~ is a shortcut for your home directory /home/$USER or /home/zanna in my case. You can omit it if the current working directory is your home directory - you can see this from your prompt

zanna@monster:~$
              ^--the ~ here is where I am - home!

You can add the -v (verbose) flag to make cp report each copy being performed:

$ cp -vr stuff backup/stuff-backup
'stuff/thing1' -> 'backup/stuff-backup/thing1'
'stuff/thing2' -> 'backup/stuff-backup/thing2
...
2 of 7
16

The command you need is simply cp which stands for "copy".

You can use it for example with one of these syntaxes:

cp SOURCEFILE TARGETFILE
cp SOURCEFILE TARGETDIRECTORY

The first variant allows you to specify a new file name for the target file, while the second variant creates a copy with the same name in the target directory. You must of course substitute the place holders in capital letters with valid paths first.

However, cp by default operates on files only, not on directories. To get it to copy a complete directory with all its content recursively, you must add the -r option:

cp -r SOURCEDIRECTORY TARGETDIRECTORY

You can learn more about the cp command by typing man cp in your terminal.

๐ŸŒ
Medium
medium.com โ€บ @justanotherdevopsmaster โ€บ bash-copy-files-from-one-folder-to-another-3b2ffde16e0c
BASH โ€” Copy files from one folder to another | by Just another devops master | Medium
May 1, 2020 - MKV="*.mkv" # because I want to find all .mkv files FROM_FOLDER=Counterpart # name of the subfolder is called Counterpart readarray RFILES < <(find $FROM_FOLDER -type f -name "$MKV")RFILES=$( find $FROM_FOLDER -type f -name "$MKV" )mkdir -p ../Desktop/destination #create folder called destination for files in "${RFILES[@]}"do files=$(basename "$files") echo $files cp "$FROM_FOLDER"/"$files" ../Desktop/destination/ done ยท readarray : its a bash command to push elements in the array.
๐ŸŒ
Experts Exchange
experts-exchange.com โ€บ questions โ€บ 29258276 โ€บ Shell-script-to-copy-files.html
Solved: Shell script to copy files | Experts Exchange
April 17, 2023 - Not sure why you need steps 2 and 3. The can be done easy enough, just shouldn't be a need. Assuming the space in the txt file is a typo, see if this does what you want: #!/bin/bash DEST_DIR=/home/user/files while read f; do cp $f $DEST_DIR done < file_path.txt
๐ŸŒ
Linode
linode.com โ€บ docs โ€บ guides โ€บ how-to-copy-files-and-directories-in-linux
How to Copy Files and Directories in Linux | Linode Docs
July 18, 2022 - Be very careful when copying any files owned by root, especially those in the system / directories. cd /etc sudo cp bash.bashrc bash.bashrc.bak ls -l bash.*
๐ŸŒ
Warp
warp.dev โ€บ terminus โ€บ linux-copy-file
Warp: How To Copy Files In Linux
May 7, 2024 - To preserve the file permissions, ownership, and timestamps, you can use the cp command with the -p flag as follows: Alternatively, you can selectively preserve specific attributes using the --preserve flag as follows: ... For example, this ...