Skip to main content
deleted 129 characters in body
Source Link
terdon
  • 252.7k
  • 69
  • 481
  • 719

Don't copy the folder, only copy the contents:

## Create the target directory. The -p suppresses error messages ## if the directory already exists mkdir -p outputFolder ## Copy the contents recursively, this will not recreate the parent cp -R inputfolder/* outputfolder/ 

This way you both ensure that the target directory is created the first time the script runs and avoid the issue when running it a second time.

Chris Down very correctly points out that in bash, this will skip files whose name starts with a .. To avoid this, you can run shopt -s dotglob before running the command above. Alternatively, and for other shells, you can include them explicitly:

cp -R inputfolder/* inputfolder/.* outputfolder/ 

Both -p for mkdir and -R for cp are defined by POSIX so this should be perfectly portable.

Don't copy the folder, only copy the contents:

## Create the target directory. The -p suppresses error messages ## if the directory already exists mkdir -p outputFolder ## Copy the contents recursively, this will not recreate the parent cp -R inputfolder/* outputfolder/ 

This way you both ensure that the target directory is created the first time the script runs and avoid the issue when running it a second time.

Chris Down very correctly points out that in bash, this will skip files whose name starts with a .. To avoid this, you can run shopt -s dotglob before running the command above. Alternatively, and for other shells, you can include them explicitly:

cp -R inputfolder/* inputfolder/.* outputfolder/ 

Both -p for mkdir and -R for cp are defined by POSIX so this should be perfectly portable.

Don't copy the folder, only copy the contents:

## Create the target directory. The -p suppresses error messages ## if the directory already exists mkdir -p outputFolder ## Copy the contents recursively, this will not recreate the parent cp -R inputfolder/* outputfolder/ 

This way you both ensure that the target directory is created the first time the script runs and avoid the issue when running it a second time.

Chris Down very correctly points out that in bash, this will skip files whose name starts with a .. To avoid this, you can run shopt -s dotglob before running the command above.

Both -p for mkdir and -R for cp are defined by POSIX so this should be perfectly portable.

added 321 characters in body
Source Link
terdon
  • 252.7k
  • 69
  • 481
  • 719

Don't copy the folder, only copy the contents:

## Create the target directory. The -p suppresses error messages ## if the directory already exists mkdir -p outputFolder ## Copy the contents recursively, this will not recreate the parent cp -R inputfolder/* outputfolder/ 

This way you both ensure that the target dirdirectory is created the first time the script runs and avoid the issue when running it a second time.

Chris Down very correctly points out that in bash, this will skip files whose name starts with a .. To avoid this, you can run shopt -s dotglob before running the command above. Alternatively, and for other shells, you can include them explicitly:

cp -R inputfolder/* inputfolder/.* outputfolder/ 

Both -p for mkdir and -R for cp are defined by POSIX so this should be perfectly portable.

Don't copy the folder, only copy the contents:

## Create the target directory. The -p suppresses error messages ## if the directory already exists mkdir -p outputFolder ## Copy the contents recursively, this will not recreate the parent cp -R inputfolder/* outputfolder/ 

This way you both ensure that the target dir is created the first time the script runs and avoid the issue when running it a second time.

Both -p for mkdir and -R for cp are defined by POSIX so this should be perfectly portable.

Don't copy the folder, only copy the contents:

## Create the target directory. The -p suppresses error messages ## if the directory already exists mkdir -p outputFolder ## Copy the contents recursively, this will not recreate the parent cp -R inputfolder/* outputfolder/ 

This way you both ensure that the target directory is created the first time the script runs and avoid the issue when running it a second time.

Chris Down very correctly points out that in bash, this will skip files whose name starts with a .. To avoid this, you can run shopt -s dotglob before running the command above. Alternatively, and for other shells, you can include them explicitly:

cp -R inputfolder/* inputfolder/.* outputfolder/ 

Both -p for mkdir and -R for cp are defined by POSIX so this should be perfectly portable.

Source Link
terdon
  • 252.7k
  • 69
  • 481
  • 719

Don't copy the folder, only copy the contents:

## Create the target directory. The -p suppresses error messages ## if the directory already exists mkdir -p outputFolder ## Copy the contents recursively, this will not recreate the parent cp -R inputfolder/* outputfolder/ 

This way you both ensure that the target dir is created the first time the script runs and avoid the issue when running it a second time.

Both -p for mkdir and -R for cp are defined by POSIX so this should be perfectly portable.