#] #] ********************* #] "$d_SysMaint"'Linux/cp notes.txt' www.BillHowewll.ca 05Aug2017 initial To view this file - use a text editor (not word processor) constant width font (eg courrier be careful of putting everything as a subdir of intended dir!! $ find "$dinn" -maxdepth 1 -type f -name "*.*" | tr \\n \\0 | xargs -0 -IFILE cp -p "FILE" "$d_Arx" 24************************24 #24************************24 # Table of Contents, generated with : # $ grep "^#]" "$d_SysMaint"'Linux/cp notes.txt' | sed "s/^#\]/ /" # ********************* "$d_SysMaint"'Linux/cp notes.txt' 06Mar2023 search 'Linux cp and how do I copy all files in a directory to another directory?' 06Mar2023 cp example : van_collision_lawsuit_Arx 07Jul2022 cp isn't overwriting, has no alias (# alias), but is a very common problem #24************************24 # options -p same as --preserve=mode,ownership,timestamps -R, -r, --recursive copy directories recursively -u, --update copy only when the SOURCE file is newer than the destination file or when the destination file is missing -> is not important for a "new" cp, but is a good habit #24************************24 08********08 #] ??Mar2023 08********08 #] ??Mar2023 08********08 #] ??Mar2023 08********08 #] ??Mar2023 08********08 #] 06Mar2023 search 'Linux cp and how do I copy all files in a directory to another directory?' +-----+ https://askubuntu.com/questions/1225926/copy-all-files-from-one-folder-to-another-in-linux Copy all files from one folder to another in linux Asked 2 years, 11 months ago Modified 2 years, 11 months ago Viewed 23k times Option 1 You can try the following trick and change your command to cp sourceDir/*.* destDir it will only copy files in the same folder, as long as they have the format like filename.ext. Make sure you have not folder with the same format. Option 2 Otherwise you try the following command: find /sourceDir/ -type f -execdir cp "{}" /destDir/ ";" It will search for all files inside the sourceDir and then copies them to the destDir. answered Apr 10, 2020 at 15:20 f0sh you can do find /sourceDir/ -type f -execdir cp -t /destDir/ {} + to avoid call cp command for every single file found. see What is the difference between using '+' (plus) and ';' (semicolon) in -exec command? – αғsнιη Apr 10, 2020 at 17:51 this won't preserve hierarchy structure – HosseyNJF Nov 10, 2020 at 14:03 first command only copy files, not copying folders and subfolders – Fernando Torres Mar 2, 2021 at 5:59 08********08 #] 06Mar2023 cp example : van_collision_lawsuit_Arx "$d_bin"'van collision lawsuit processes.sh' # van_collision_lawsuit_Arx() - backup project files van_collision_lawsuit_Arx() { date_ymdhm=$(date +"%y%m%d %kh%Mm") dinn="$d_web"'Personal/210611 Hoffart lawsuit/' d_Arx="$dinn"'z_Archive/'"$date_ymdhm/" # no trailing `/ ?? echo "date_ymdhm: $date_ymdhm" echo "d_Arx: $d_Arx" if ! [ -d d_Arx ]; then mkdir "$d_Arx"; fi find "$dinn" -maxdepth 1 -type f -name "*.*" | tr \\n \\0 | xargs -0 -IFILE cp -p "FILE" "$d_Arx" } 08********08 #] 07Jul2022 cp isn't overwriting, has no alias (# alias), but is a very common problem "$d_bin""fileops.sh" -> dinn_finn_strP_replace() I tried, but nothing worked!!?? : # 07Jul2022 can't get [cp, mv] to work? However, correct substitute IS DONE in $ptmp!!?? # add a delay - didn't work # sleep 5s # cp "$ptmp" "$d_inn$finn" # yes | cp "$ptmp" "$d_inn$finn" # \cp "$ptmp" "$d_inn$finn" # cp -nf "$ptmp" "$d_inn$finn" /bin/cp "$ptmp" "$d_inn$finn" # mv "$ptmp" "$d_inn$finn" # mv -f "$ptmp" "$d_inn$finn" +-----+ https://stackoverflow.com/questions/8488253/how-to-force-cp-to-overwrite-without-confirmation +--+ As some of the other answers have stated, you probably use an alias somewhere which maps cp to cp -i or something similar. You can run a command without any aliases by preceding it with a backslash. In your case, try \cp -r /zzz/zzz/* /xxx/xxx The backslash will temporarily disable any aliases you have called cp. answered Dec 13, 2011 at 11:30 user avatar Chris +--+ As other answers have stated, this could happend if cp is an alias of cp -i. You can append a \ before the cp command to use it without alias. \cp -fR source target answered Jul 29, 2016 at 2:19 user avatar Arnold Roa +--+ So I run into this a lot because I keep cp aliased to cp -iv, and I found a neat trick. It turns out that while -i and -n both cancel previous overwrite directives, -f does not. However, if you use -nf it adds the ability to clear the -i. So: cp -f /foo/* /bar <-- Prompt cp -nf /foo/* /bar <-- No Prompt Pretty neat huh? /necropost answered Feb 17, 2020 at 20:20 user avatar Adam McCormick +--+ The simplest way for me: yes | cp source destination answered Oct 21, 2021 at 6:39 user avatar malcolm ******************* 31Oct2018 [HOWELL_BASE, Thunderbird] too slow - cp Thunderbird to SWAPPER $ cp -ru "/media/bill/HOWELL_BASE/Thunderbird/." "/media/bill/SWAPPER/Thunderbird" cp: cannot stat ‘/media/bill/HOWELL_BASE/Thunderbird/./n4caryuo.default/lock’: Input/output error cp: cannot stat ‘/media/bill/HOWELL_BASE/Thunderbird/./n4caryuo.default/extensions.json’: Input/output error >> oops dates not preserved be careful of putting everything as a subdir of intended dir!! should be $ cp -rup "/media/bill/HOWELL_BASE/Thunderbird/." "/media/bill/SWAPPER/Thunderbird" u - is not important for a "new" cp, but is a good habit p - DON'T USE - for webPages!! ******************** 05Aug2017 cp -r ~/folder1/. ~/new_folder1 https://askubuntu.com/questions/86822/how-can-i-copy-the-contents-of-a-folder-to-another-folder-in-a-different-directo Lets say you have a folder called folder1 in your ~, inside folder1 is 1 file called file1 and 2 folders called sub1 and sub2 each with other files and folders inside them. To copy all the contents of ~/folder1 to ~/new_folder1 you would use cp -r ~/folder1/. ~/new_folder1 new_folder1 would then contain all the files and folders from folder1. cp is the command to copy using a terminal, -r makes it recursively (so, current directory + further directories inside current) ~/folder1 is the origin folder, ~/new_folder1 is the destination folder for the files/folders inside the origin. edited Dec 11 '11 at 14:10 answered Dec 11 '11 at 1:23, Bruno Pereira # enddoc