1. Skip to Menu
  2. Skip to Content
  3. Skip to Footer

DIAS is a portal that can help you get your work done

Αυτή η υπηρεσία μπορεί να σας βοηθήσει να γίνετε πιο αποτελεσματικοί στην τάξη και στο μάθημα σας γενικότερα...

Ubuntu, Copy one file to many subfolders?

Ubuntu How do I Copy one file to many subfolders?
-----------------------------------------------------------------------

Answers
------------

1. If the folders are in the same folder that the file exists, then use:

for dir in *; do [ -d "$dir" ] && cp YOURFILE.EXT "$dir" ; done

2. In other scenery, if the file is in a different path, use:

for i in folder1 folder2 folder3 folder4; do cp YOURFILE.EXT $i; done

Glossary:

YOURFILE.EXT = The name of your file, may contain the full path.
folder1 folder[...] = the name of the folders where to drop the file,
-- folder names may contain the full path.


Ubuntu How do I Copy one file to all subfolders?
------------------------------------------------------------------

Answers
------------


1. This will copy php.ini from /var/www to all subfolders maximum depth 1 under /var/www

for dir in $(find /var/www/ -type d -maxdepth 1); do cp -i /var/www/php.ini "$dir"/; done

2. This will copy php.ini from /var/www to all subfolders under /var/www

for dir in $(find /var/www/ -type d); do cp -i /var/www/php.ini "$dir"/; done

3. This will also do the same as the previous command

find /var/www -type d -exec cp -i /var/www/php.ini {} \;